feat: upgrade nextjs
This commit is contained in:
1 parent
750d5b12c8
commit
29f6de300b
16 files changed
+365
-344
No files matched your search
@@ -1,22 +1,18 @@
|
||||
'use client';
|
||||
|
||||
import { FC, useEffect, useRef, useState } from 'react';
|
||||
import { DropdownMenuItem } from '@radix-ui/react-dropdown-menu';
|
||||
import { motion } from 'framer-motion';
|
||||
import { Menu } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { usePathname } from 'next/navigation';
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Drawer,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerDescription,
|
||||
DrawerHeader,
|
||||
DrawerTitle,
|
||||
DrawerTrigger
|
||||
} from '@/components/ui/drawer';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const paths = [
|
||||
{ path: '/', title: 'Random' },
|
||||
{ path: '/popular', title: 'Popular' },
|
||||
{ path: '/top', title: 'Top rated' },
|
||||
{ path: '/favorites', title: 'Favorites' }
|
||||
@@ -27,58 +23,59 @@ export function MobileNavigation() {
|
||||
|
||||
return (
|
||||
<div className='flex xs:hidden'>
|
||||
<Drawer>
|
||||
<DrawerTrigger asChild>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size='icon'>
|
||||
<Menu size={19} />
|
||||
</Button>
|
||||
</DrawerTrigger>
|
||||
<DrawerContent>
|
||||
<DrawerHeader className='pointer-events-none absolute'>
|
||||
<DrawerTitle />
|
||||
<DrawerDescription />
|
||||
</DrawerHeader>
|
||||
<ul className='flex flex-col gap-2 p-2'>
|
||||
{paths.map(({ path, title }) => (
|
||||
<li key={path}>
|
||||
<Link href={path} shallow>
|
||||
<div>
|
||||
<DrawerClose asChild>
|
||||
<Button className='w-full relative' variant={currentPath === path ? 'default' : 'outline'}>
|
||||
{title}
|
||||
</Button>
|
||||
</DrawerClose>
|
||||
</div>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className='w-44 flex flex-col gap-2 p-2'>
|
||||
{paths.map(({ path, title }) => (
|
||||
<DropdownMenuItem key={path} asChild>
|
||||
<Link href={path}>
|
||||
<div>
|
||||
<Button className='w-full relative' variant={currentPath === path ? 'default' : 'outline'}>
|
||||
{title}
|
||||
</Button>
|
||||
</div>
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function DesktopNavigation() {
|
||||
const [position, setPosition] = useState({ left: 0, width: 0, opacity: 0 });
|
||||
const currentRef = useRef<HTMLLIElement>(null);
|
||||
const currentPath = usePathname();
|
||||
|
||||
useEffect(() => {
|
||||
const link = currentRef.current;
|
||||
|
||||
setPosition({ width: link?.clientWidth || 0, left: link?.offsetLeft || 0, opacity: link ? 1 : 0 });
|
||||
}, [currentPath]);
|
||||
|
||||
return (
|
||||
<ul className='hidden xs:flex items-center whitespace-nowrap text-sm gap-3'>
|
||||
<ul className='relative hidden xs:flex items-center whitespace-nowrap text-sm gap-3'>
|
||||
{paths.map(({ path, title }) => (
|
||||
<li key={path} className={currentPath === path ? undefined : 'cursor-pointer'}>
|
||||
<Link href={path} shallow passHref legacyBehavior>
|
||||
<div>
|
||||
{currentPath === path ? (
|
||||
<Badge className='text-sm font-normal pointer-events-none' variant='secondary'>
|
||||
{title}
|
||||
</Badge>
|
||||
) : (
|
||||
title
|
||||
)}
|
||||
</div>
|
||||
<li
|
||||
key={path}
|
||||
ref={currentPath !== path ? undefined : currentRef}
|
||||
className={cn('mix-blend-difference text-white z-10 px-2.5 py-0.5', currentPath !== path && 'cursor-pointer')}
|
||||
>
|
||||
<Link href={path}>
|
||||
<div>{title}</div>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
<Cursor position={position} />
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
const Cursor: FC<{ position: { left: number; width: number; opacity: number } }> = ({ position }) => {
|
||||
return <motion.li className='pointer-events-none absolute bg-primary rounded-full h-full z-0' animate={position} />;
|
||||
};
|
||||
Reference in new issue
Block a user