|
@@ -1,9 +1,9 @@
|
|
|
import Link from "next/link";
|
|
import Link from "next/link";
|
|
|
|
|
+import {Suspense} from "react";
|
|
|
import LogoIcon from "@components/common/icons/LogoIcon";
|
|
import LogoIcon from "@components/common/icons/LogoIcon";
|
|
|
import MobileMenuTrigger from "./MobileMenuTrigger";
|
|
import MobileMenuTrigger from "./MobileMenuTrigger";
|
|
|
import { NavbarActions } from "./NavbarActions";
|
|
import { NavbarActions } from "./NavbarActions";
|
|
|
import { NavbarErrorBoundary } from "@/components/error/ErrorBoundary";
|
|
import { NavbarErrorBoundary } from "@/components/error/ErrorBoundary";
|
|
|
-
|
|
|
|
|
import {
|
|
import {
|
|
|
GET_TREEFRONT_MENUS } from "@/graphql";
|
|
GET_TREEFRONT_MENUS } from "@/graphql";
|
|
|
import { serverGraphqlFetch } from "@utils/bagisto/index";
|
|
import { serverGraphqlFetch } from "@utils/bagisto/index";
|
|
@@ -13,29 +13,29 @@ import { auth } from "@/utils/auth/auth-helper";
|
|
|
import TopSwiperBanner from "./TopSwiperBanner"
|
|
import TopSwiperBanner from "./TopSwiperBanner"
|
|
|
import { restApiFetch } from "@utils/bagisto/index";
|
|
import { restApiFetch } from "@utils/bagisto/index";
|
|
|
import type { AnnouncementItem } from "./TopSwiperBanner";
|
|
import type { AnnouncementItem } from "./TopSwiperBanner";
|
|
|
|
|
+import type { RestfulGetThemeCustomizations } from '@/types/theme/theme-customization';
|
|
|
export default async function Navbar() {
|
|
export default async function Navbar() {
|
|
|
// 2. 服务端 fetch 请求我们自己的 Next.js API
|
|
// 2. 服务端 fetch 请求我们自己的 Next.js API
|
|
|
- const res = await restApiFetch({
|
|
|
|
|
|
|
+ const topBarPromise:Promise<AnnouncementItem[]> = restApiFetch<{data:RestfulGetThemeCustomizations}>({
|
|
|
api: `/shop/theme-customizations?name=Top_Bar`,
|
|
api: `/shop/theme-customizations?name=Top_Bar`,
|
|
|
method: "GET",
|
|
method: "GET",
|
|
|
isRoute: false,
|
|
isRoute: false,
|
|
|
takeAuthorization: false,
|
|
takeAuthorization: false,
|
|
|
-
|
|
|
|
|
- });
|
|
|
|
|
- let topBarData: AnnouncementItem[] = [];
|
|
|
|
|
- try {
|
|
|
|
|
- // 安全取值链
|
|
|
|
|
- const themeItem = res?.body?.[0];
|
|
|
|
|
|
|
+ }).then((result) => {
|
|
|
|
|
+ const themeItem = result.body[0];
|
|
|
const optionsStr = themeItem?.translation?.options;
|
|
const optionsStr = themeItem?.translation?.options;
|
|
|
if (optionsStr) {
|
|
if (optionsStr) {
|
|
|
const parsed = JSON.parse(optionsStr);
|
|
const parsed = JSON.parse(optionsStr);
|
|
|
- topBarData = parsed?.images ?? [];
|
|
|
|
|
|
|
+ return parsed?.images ?? [];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return [];
|
|
|
}
|
|
}
|
|
|
- } catch (err) {
|
|
|
|
|
- console.error("解析 translation.options 失败", err);
|
|
|
|
|
- topBarData = [];
|
|
|
|
|
- }
|
|
|
|
|
- console.log('topbar-res----------------------------:',res);
|
|
|
|
|
|
|
+ }).catch((err) => {
|
|
|
|
|
+ // 获取top_bar失败不应该阻止用户访问网站
|
|
|
|
|
+ console.error('get top_bar error: ', err);
|
|
|
|
|
+ return [];
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
|
|
|
const session = await auth();// 游客是null
|
|
const session = await auth();// 游客是null
|
|
|
const isGuest = session === null;
|
|
const isGuest = session === null;
|
|
@@ -44,6 +44,7 @@ export default async function Navbar() {
|
|
|
GetTreefrontMenusResult
|
|
GetTreefrontMenusResult
|
|
|
>({
|
|
>({
|
|
|
query: GET_TREEFRONT_MENUS,
|
|
query: GET_TREEFRONT_MENUS,
|
|
|
|
|
+ takeAuthorization: false,
|
|
|
});
|
|
});
|
|
|
console.log('GetTreefrontMenusResult --- ',menudata)
|
|
console.log('GetTreefrontMenusResult --- ',menudata)
|
|
|
const menudatas =menudata? menudata.treefrontMenus:[];
|
|
const menudatas =menudata? menudata.treefrontMenus:[];
|
|
@@ -51,7 +52,9 @@ export default async function Navbar() {
|
|
|
return (
|
|
return (
|
|
|
<NavbarErrorBoundary>
|
|
<NavbarErrorBoundary>
|
|
|
<header className="sticky top-0 z-10">
|
|
<header className="sticky top-0 z-10">
|
|
|
- <TopSwiperBanner items={topBarData} />
|
|
|
|
|
|
|
+ <Suspense fallback={<div className="flex items-center justify-center h-10 w-full overflow-hidden bg-ly-middlegreen text-ly-14 text-white">Loading top bar...</div>}>
|
|
|
|
|
+ <TopSwiperBanner topBarPromise={topBarPromise} />
|
|
|
|
|
+ </Suspense>
|
|
|
<nav className="relative flex flex-col items-center justify-between gap-4 bg-neutral-50 p-4 pt-3 pb-3 dark:bg-neutral-900 md:flex-row lg:px-6 lg:py-4">
|
|
<nav className="relative flex flex-col items-center justify-between gap-4 bg-neutral-50 p-4 pt-3 pb-3 dark:bg-neutral-900 md:flex-row lg:px-6 lg:py-4">
|
|
|
<div className="flex w-full items-center justify-between gap-0 sm:gap-4">
|
|
<div className="flex w-full items-center justify-between gap-0 sm:gap-4">
|
|
|
{/* 1. THE STATIC SHELL (Visible Instantly) */}
|
|
{/* 1. THE STATIC SHELL (Visible Instantly) */}
|