fix : dedupe code
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import Image from "@/components/ui/resilient-image";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
import {
|
import {
|
||||||
@@ -15,24 +14,13 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { PublicAccountMenu } from "@/components/public/public-account-menu";
|
import { HeaderShell } from "@/components/header-shell";
|
||||||
import { NotificationBell } from "@/components/notifications/notification-bell";
|
|
||||||
import { ThemeSwitcher } from "@/components/theme-switcher";
|
|
||||||
|
|
||||||
export function AdminHeader() {
|
export function AdminHeader() {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
|
||||||
return (<>
|
return (
|
||||||
<header className="border-b bg-background/95 supports-backdrop-filter:backdrop-blur">
|
<HeaderShell homeHref="/admin" homeLabel="หน้าแอดมิน ไกด์เกนชินไม่ใช่เกมมือถือ">
|
||||||
<div className="mx-auto flex min-h-16 w-full max-w-7xl flex-nowrap items-center gap-2 px-4 py-2 sm:px-6">
|
|
||||||
<Link
|
|
||||||
href="/admin"
|
|
||||||
aria-label="หน้าแอดมิน ไกด์เกนชินไม่ใช่เกมมือถือ"
|
|
||||||
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 lg:inline">ไกด์เกนชินไม่ใช่เกมมือถือ</span>
|
|
||||||
</Link>
|
|
||||||
<nav aria-label="เมนูแอดมิน" className="flex min-w-0 flex-1 items-center gap-1 overflow-x-auto sm:justify-end">
|
<nav aria-label="เมนูแอดมิน" className="flex min-w-0 flex-1 items-center gap-1 overflow-x-auto sm:justify-end">
|
||||||
<Button variant={pathname.startsWith("/admin/comments") ? "secondary" : "ghost"} size="sm" nativeButton={false}
|
<Button variant={pathname.startsWith("/admin/comments") ? "secondary" : "ghost"} size="sm" nativeButton={false}
|
||||||
render={<Link href="/admin/comments" prefetch={false} />} aria-label="ความคิดเห็น">
|
render={<Link href="/admin/comments" prefetch={false} />} aria-label="ความคิดเห็น">
|
||||||
@@ -105,11 +93,6 @@ export function AdminHeader() {
|
|||||||
<ExternalLinkIcon />
|
<ExternalLinkIcon />
|
||||||
</Button>
|
</Button>
|
||||||
</nav>
|
</nav>
|
||||||
<ThemeSwitcher />
|
</HeaderShell>
|
||||||
<NotificationBell />
|
|
||||||
<PublicAccountMenu />
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import type { ReactNode } from "react";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
import Image from "@/components/ui/resilient-image";
|
||||||
|
import { PublicAccountMenu } from "@/components/public/public-account-menu";
|
||||||
|
import { NotificationBell } from "@/components/notifications/notification-bell";
|
||||||
|
import { ThemeSwitcher } from "@/components/theme-switcher";
|
||||||
|
|
||||||
|
export function HeaderShell({ homeHref, homeLabel, children }: {
|
||||||
|
homeHref: string;
|
||||||
|
homeLabel: string;
|
||||||
|
children: ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<header className="border-b bg-background/95 supports-backdrop-filter:backdrop-blur">
|
||||||
|
<div className="mx-auto flex min-h-16 w-full max-w-7xl flex-nowrap items-center gap-2 px-4 py-2 sm:px-6">
|
||||||
|
<Link
|
||||||
|
href={homeHref}
|
||||||
|
aria-label={homeLabel}
|
||||||
|
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 lg:inline">ไกด์เกนชินไม่ใช่เกมมือถือ</span>
|
||||||
|
</Link>
|
||||||
|
{children}
|
||||||
|
<ThemeSwitcher />
|
||||||
|
<NotificationBell />
|
||||||
|
<PublicAccountMenu />
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import Image from "@/components/ui/resilient-image";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Suspense } from "react";
|
import { Suspense } from "react";
|
||||||
import { PencilIcon } from "lucide-react";
|
import { PencilIcon } from "lucide-react";
|
||||||
@@ -6,9 +5,7 @@ import { PencilIcon } from "lucide-react";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { VisitorPresence } from "@/components/public/visitor-presence";
|
import { VisitorPresence } from "@/components/public/visitor-presence";
|
||||||
import { PublicNavigation } from "@/components/public/public-navigation";
|
import { PublicNavigation } from "@/components/public/public-navigation";
|
||||||
import { PublicAccountMenu } from "@/components/public/public-account-menu";
|
import { HeaderShell } from "@/components/header-shell";
|
||||||
import { NotificationBell } from "@/components/notifications/notification-bell";
|
|
||||||
import { ThemeSwitcher } from "@/components/theme-switcher";
|
|
||||||
import { getAdminSession } from "@/lib/auth/server";
|
import { getAdminSession } from "@/lib/auth/server";
|
||||||
import { HttpError } from "@/lib/security/http";
|
import { HttpError } from "@/lib/security/http";
|
||||||
|
|
||||||
@@ -30,16 +27,7 @@ async function AdminEditLink({ editHref }: { editHref: string }) {
|
|||||||
|
|
||||||
export function SiteHeader({ editHref = "/admin", guideId }: { editHref?: string; guideId?: string } = {}) {
|
export function SiteHeader({ editHref = "/admin", guideId }: { editHref?: string; guideId?: string } = {}) {
|
||||||
return (
|
return (
|
||||||
<header className="border-b bg-background/95 supports-backdrop-filter:backdrop-blur">
|
<HeaderShell homeHref="/" homeLabel="หน้าแรก ไกด์เกนชินไม่ใช่เกมมือถือ">
|
||||||
<div className="mx-auto flex min-h-16 w-full max-w-7xl flex-nowrap items-center gap-2 px-4 py-2 sm:px-6">
|
|
||||||
<Link
|
|
||||||
href="/"
|
|
||||||
aria-label="หน้าแรก ไกด์เกนชินไม่ใช่เกมมือถือ"
|
|
||||||
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 lg:inline">ไกด์เกนชินไม่ใช่เกมมือถือ</span>
|
|
||||||
</Link>
|
|
||||||
<PublicNavigation />
|
<PublicNavigation />
|
||||||
<div className="hidden lg:block">
|
<div className="hidden lg:block">
|
||||||
<VisitorPresence guideId={guideId} />
|
<VisitorPresence guideId={guideId} />
|
||||||
@@ -47,10 +35,6 @@ export function SiteHeader({ editHref = "/admin", guideId }: { editHref?: string
|
|||||||
<Suspense fallback={null}>
|
<Suspense fallback={null}>
|
||||||
<AdminEditLink editHref={editHref} />
|
<AdminEditLink editHref={editHref} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
<ThemeSwitcher />
|
</HeaderShell>
|
||||||
<NotificationBell />
|
|
||||||
<PublicAccountMenu />
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user