From 0fa4a62007044ab75568e7e49486be723ee67c45 Mon Sep 17 00:00:00 2001 From: besscroft Date: Mon, 6 May 2024 23:19:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/layout/DynamicDropMenu.tsx | 47 +++--- components/layout/DynamicNavbar.tsx | 9 +- components/layout/Header.tsx | 6 +- components/layout/HeaderLink.tsx | 13 +- components/ui/DropdownMenu.tsx | 200 ++++++++++++++++++++++++++ package.json | 1 + pnpm-lock.yaml | 58 ++++++-- types/index.ts | 4 + 8 files changed, 280 insertions(+), 58 deletions(-) create mode 100644 components/ui/DropdownMenu.tsx diff --git a/components/layout/DynamicDropMenu.tsx b/components/layout/DynamicDropMenu.tsx index 43321ac..494b087 100644 --- a/components/layout/DynamicDropMenu.tsx +++ b/components/layout/DynamicDropMenu.tsx @@ -1,42 +1,35 @@ 'use client' -import { Dropdown, DropdownItem, DropdownMenu, DropdownTrigger } from '@nextui-org/react' import { useRouter } from 'next-nprogress-bar' import { usePathname } from 'next/navigation' import { Aperture } from 'lucide-react' -import { HandleProps, TagType } from '~/types' -import { useSWRHydrated } from '~/hooks/useSWRHydrated' +import { DataProps, TagType } from '~/types' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger +} from '~/components/ui/DropdownMenu' -export default function DynamicDropMenu(props: Readonly) { +export default function DynamicDropMenu(props: Readonly) { const router = useRouter() const pathname = usePathname() - const { data } = useSWRHydrated(props) return ( - - - - - - router.push('/')} - className={pathname === '/' ? 'text-blue-600' : ''} - > - 首页 - - {data && Array.isArray(data) && data?.map((tag: TagType, index: any, array: TagType[]) => ( - + + + router.push('/')}>首页 + + {Array.isArray(props.data) && props.data?.map((tag: TagType, index: any, array: TagType[]) => ( + router.push(tag.tag_value)} - className={pathname === tag.tag_value ? 'text-blue-600' : ''} - > - {tag.name} - + className={pathname === tag.tag_value ? 'bg-gray-100' : ''} + >{tag.name} ))} - - + + ) } \ No newline at end of file diff --git a/components/layout/DynamicNavbar.tsx b/components/layout/DynamicNavbar.tsx index 21b81ab..1379f99 100644 --- a/components/layout/DynamicNavbar.tsx +++ b/components/layout/DynamicNavbar.tsx @@ -2,7 +2,7 @@ import VaulDrawer from '~/components/layout/VaulDrawer' import { DropMenu } from '~/components/layout/DropMenu' import DynamicDropMenu from '~/components/layout/DynamicDropMenu' import { fetchTagsShow } from '~/server/lib/query' -import { HandleProps } from '~/types' +import { DataProps } from '~/types' export default async function DynamicNavbar() { const getData = async () => { @@ -10,9 +10,10 @@ export default async function DynamicNavbar() { return await fetchTagsShow() } - const props: HandleProps = { - handle: getData, - args: 'headerLink', + const data = await getData() + + const props: DataProps = { + data: data } return ( diff --git a/components/layout/Header.tsx b/components/layout/Header.tsx index e9f3a30..9fdd48f 100644 --- a/components/layout/Header.tsx +++ b/components/layout/Header.tsx @@ -3,7 +3,7 @@ import Logo from '~/components/layout/Logo' import DynamicNavbar from '~/components/layout/DynamicNavbar' import HeaderLink from '~/components/layout/HeaderLink' import { fetchTagsShow } from '~/server/lib/query' -import { LinkProps } from '~/types' +import { DataProps } from '~/types' export default async function Header() { const getData = async () => { @@ -13,9 +13,7 @@ export default async function Header() { const data = await getData() - const props: LinkProps = { - handle: getData, - args: 'headerLink', + const props: DataProps = { data: data } diff --git a/components/layout/HeaderLink.tsx b/components/layout/HeaderLink.tsx index 5a1dc4e..de762b6 100644 --- a/components/layout/HeaderLink.tsx +++ b/components/layout/HeaderLink.tsx @@ -1,19 +1,14 @@ 'use client' import { Button } from '@nextui-org/react' -import { TagType, LinkProps } from '~/types' +import { TagType } from '~/types' import { usePathname } from 'next/navigation' import { useRouter } from 'next-nprogress-bar' -import useSWR from 'swr' +import { DataProps } from '~/types' -export default function HeaderLink(props: Readonly) { - const { data } = useSWR(props.args, - () => { - return props.handle - }, { revalidateOnFocus: false, fallbackData: props.data }) +export default function HeaderLink(props: Readonly) { const pathname = usePathname() const router = useRouter() - return ( <> - {Array.isArray(data) && data?.map((tag: TagType) => ( + {Array.isArray(props.data) && props.data?.map((tag: TagType) => (