41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import Link from "next/link";
|
|
import { Suspense } from "react";
|
|
import { PencilIcon } from "lucide-react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { VisitorPresence } from "@/components/public/visitor-presence";
|
|
import { PublicNavigation } from "@/components/public/public-navigation";
|
|
import { HeaderShell } from "@/components/header-shell";
|
|
import { getAdminSession } from "@/lib/auth/server";
|
|
import { HttpError } from "@/lib/security/http";
|
|
|
|
async function AdminEditLink({ editHref }: { editHref: string }) {
|
|
let isAdmin = false;
|
|
try {
|
|
isAdmin = Boolean(await getAdminSession());
|
|
} catch (cause) {
|
|
if (!(cause instanceof HttpError) || cause.status !== 503) throw cause;
|
|
}
|
|
|
|
return isAdmin ? (
|
|
<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;
|
|
}
|
|
|
|
export function SiteHeader({ editHref = "/admin", guideId }: { editHref?: string; guideId?: string } = {}) {
|
|
return (
|
|
<HeaderShell homeHref="/" homeLabel="หน้าแรก ไกด์เกนชินไม่ใช่เกมมือถือ">
|
|
<PublicNavigation />
|
|
<div className="hidden lg:block">
|
|
<VisitorPresence guideId={guideId} />
|
|
</div>
|
|
<Suspense fallback={null}>
|
|
<AdminEditLink editHref={editHref} />
|
|
</Suspense>
|
|
</HeaderShell>
|
|
);
|
|
}
|