feat : finallt smart
This commit is contained in:
@@ -1,28 +1,20 @@
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { Suspense } from "react";
|
||||
import { MenuIcon } from "lucide-react";
|
||||
import { PencilIcon } from "lucide-react";
|
||||
|
||||
import { Button, buttonVariants } from "@/components/ui/button";
|
||||
import { Sheet, SheetClose, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { VisitorPresence } from "@/components/public/visitor-presence";
|
||||
import { getAdminSession } from "@/lib/auth/server";
|
||||
|
||||
async function AdminEditLink({ editHref, mobile = false }: { editHref: string; mobile?: boolean }) {
|
||||
async function AdminEditLink({ editHref }: { editHref: string }) {
|
||||
const isAdmin = Boolean(await getAdminSession());
|
||||
|
||||
return isAdmin ? (
|
||||
mobile ? (
|
||||
<SheetClose
|
||||
render={<Link href={editHref} className={buttonVariants({ variant: "ghost", className: "h-11 w-full justify-start" })} />}
|
||||
>
|
||||
ไปหน้าแก้ไข
|
||||
</SheetClose>
|
||||
) : (
|
||||
<Button variant="ghost" size="sm" nativeButton={false} render={<Link href={editHref} />}>
|
||||
ไปหน้าแก้ไข
|
||||
</Button>
|
||||
)
|
||||
<Button variant="ghost" size="sm" nativeButton={false} render={<Link href={editHref} />} aria-label="ไปหน้าแก้ไข">
|
||||
<PencilIcon data-icon="inline-start" className="lg:hidden" />
|
||||
<span className="hidden lg:inline">ไปหน้าแก้ไข</span>
|
||||
</Button>
|
||||
) : null;
|
||||
}
|
||||
|
||||
@@ -36,48 +28,30 @@ export function SiteHeader({ editHref = "/admin", guideId }: { editHref?: string
|
||||
className="mr-auto flex min-h-11 shrink-0 items-center gap-3 rounded-lg font-heading font-semibold focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
>
|
||||
<Image src="/icon.png" alt="" width={36} height={36} className="size-9 object-contain" />
|
||||
<span className="hidden sm:inline">ไกด์เกนชินไม่ใช่เกมมือถือ</span>
|
||||
<span className="hidden lg:inline">ไกด์เกนชินไม่ใช่เกมมือถือ</span>
|
||||
</Link>
|
||||
<nav aria-label="Public navigation" className="hidden items-center gap-1 lg:flex">
|
||||
<Button variant="ghost" size="sm" nativeButton={false} render={<Link href="/commission" />}>
|
||||
<nav aria-label="Public navigation" className="flex min-w-0 items-center gap-1 overflow-x-auto lg:overflow-visible">
|
||||
<Button variant="ghost" size="sm" nativeButton={false} render={<Link href="/commission" />} aria-label="Commission">
|
||||
<Image src="/icon/commission.webp" alt="" width={24} height={24} className="size-6 object-contain" />
|
||||
Commission
|
||||
<span className="hidden lg:inline">Commission</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
nativeButton={false}
|
||||
render={<Link href="/stygian" />}
|
||||
aria-label="Stygian Guide"
|
||||
>
|
||||
<Image src="/icon/stygian.webp" alt="" width={24} height={24} className="size-6 object-contain" />
|
||||
Stygian Guide
|
||||
<span className="hidden lg:inline">Stygian Guide</span>
|
||||
</Button>
|
||||
<Suspense fallback={null}>
|
||||
<AdminEditLink editHref={editHref} />
|
||||
</Suspense>
|
||||
</nav>
|
||||
<VisitorPresence guideId={guideId} />
|
||||
<Sheet>
|
||||
<SheetTrigger render={<Button variant="ghost" size="icon" className="lg:hidden" aria-label="เปิดเมนู" />}>
|
||||
<MenuIcon />
|
||||
</SheetTrigger>
|
||||
<SheetContent side="right">
|
||||
<SheetHeader><SheetTitle>เมนู</SheetTitle></SheetHeader>
|
||||
<nav aria-label="Public mobile navigation" className="flex flex-col gap-1 px-3">
|
||||
<SheetClose render={<Link href="/commission" className={buttonVariants({ variant: "ghost", className: "h-11 w-full justify-start" })} />}>
|
||||
<Image src="/icon/commission.webp" alt="" width={24} height={24} className="size-6 object-contain" />
|
||||
Commission
|
||||
</SheetClose>
|
||||
<SheetClose render={<Link href="/stygian" className={buttonVariants({ variant: "ghost", className: "h-11 w-full justify-start" })} />}>
|
||||
<Image src="/icon/stygian.webp" alt="" width={24} height={24} className="size-6 object-contain" />
|
||||
Stygian Guide
|
||||
</SheetClose>
|
||||
<Suspense fallback={null}>
|
||||
<AdminEditLink editHref={editHref} mobile />
|
||||
</Suspense>
|
||||
</nav>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
<div className="hidden lg:block">
|
||||
<VisitorPresence guideId={guideId} />
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
|
||||
@@ -11,22 +11,19 @@ export function VisitorPresence({ guideId }: { guideId?: string }) {
|
||||
<div className="flex items-center gap-1" aria-live="polite">
|
||||
<Badge
|
||||
variant="secondary"
|
||||
className="tabular-nums"
|
||||
className=" tabular-nums"
|
||||
title="ผู้เข้าชมทั้งหมดที่กำลังออนไลน์"
|
||||
aria-label={`ผู้เข้าชมทั้งหมดที่กำลังออนไลน์ ${counts?.global ?? "-"}`}
|
||||
>
|
||||
<UsersIcon data-icon="inline-start" />
|
||||
<span className="hidden sm:inline">ทั้งหมด</span> {counts?.global ?? "-"}
|
||||
ทั้งหมด {counts?.global ?? "-"}
|
||||
</Badge>
|
||||
{guideId ? (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="tabular-nums"
|
||||
className=" tabular-nums"
|
||||
title="ผู้เข้าชม Guide นี้ที่กำลังออนไลน์"
|
||||
aria-label={`ผู้เข้าชม Guide นี้ที่กำลังออนไลน์ ${counts?.guide ?? "-"}`}
|
||||
>
|
||||
<span className="hidden sm:inline">ไกด์นี้</span>
|
||||
<span aria-hidden="true" className="sm:hidden">G</span> {counts?.guide ?? "-"}
|
||||
ไกด์นี้ {counts?.guide ?? "-"}
|
||||
</Badge>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user