index.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import Link from "next/link";
  2. // import { Suspense } from "react";
  3. import LogoIcon from "@components/common/icons/LogoIcon";
  4. // import MobileMenuTrigger from "./MobileMenuTrigger";
  5. import { NavbarActions } from "./NavbarActions";
  6. // import { NavigationSkeleton } from "./NavigationSkeleton";
  7. import { NavbarErrorBoundary } from "@/components/error/ErrorBoundary";
  8. import DesktopNavigation from "./DesktopNavigation";
  9. import {
  10. GET_TREEFRONT_MENUS } from "@/graphql";
  11. import { serverGraphqlFetch } from "@utils/bagisto/index";
  12. import NavbarSearchIcon from "./NavbarSearchIcon"
  13. import type { GetTreefrontMenusResult } from "@/types/theme/menus";
  14. import { authOptions } from "@utils/auth";
  15. import { getServerSession } from "next-auth";
  16. import TopSwiperBanner from "./TopSwiperBanner"
  17. export default async function Navbar() {
  18. const session = await getServerSession(authOptions);// 游客是null
  19. const isGuest = session === null;
  20. const { data: menudata } = await serverGraphqlFetch<
  21. GetTreefrontMenusResult
  22. >({
  23. query: GET_TREEFRONT_MENUS,
  24. });
  25. console.log('GetTreefrontMenusResult --- ',menudata)
  26. const menudatas =menudata? menudata.treefrontMenus:[];
  27. return (
  28. <NavbarErrorBoundary>
  29. <header className="sticky top-0 z-10">
  30. <TopSwiperBanner />
  31. <nav className="relative flex flex-col items-center justify-between gap-4 bg-neutral-50 pt-3 pb-3 dark:bg-neutral-900 md:flex-row ">
  32. <div className="flex w-full items-center justify-between max-w-[1440px] m-auto gap-0 sm:gap-4">
  33. {/* 1. THE STATIC SHELL (Visible Instantly) */}
  34. <div className="flex items-center max-w-fit gap-5 xl:gap-6">
  35. {/* 2. STATIC HOLE: Categories (Suspended) */}
  36. {/* <Suspense fallback={<NavigationSkeleton />}>
  37. <MobileMenuTrigger isGuest={isGuest} menuData={menudatas} />
  38. </Suspense> */}
  39. <div className="flex-1 justify-center flex">
  40. {/* <Suspense fallback={<SearchSkeleton />}>
  41. <Search search={false} />
  42. </Suspense> */}
  43. <NavbarSearchIcon/>
  44. </div>
  45. </div>
  46. <Link
  47. className="flex-initial h-9 w-36.5"
  48. href="/"
  49. aria-label="Go to homepage"
  50. >
  51. <LogoIcon />
  52. </Link>
  53. <NavbarActions isGuest={isGuest} />
  54. </div>
  55. </nav>
  56. <DesktopNavigation menus={menudatas}/>
  57. </header>
  58. </NavbarErrorBoundary>
  59. );
  60. }