feat: upgrade nextjs

This commit is contained in:
ner committed 2024-08-29 17:06:53 +03:00
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} />;
};
+18 -25
View File
@@ -1,4 +1,4 @@
import { FC, useMemo, useRef } from 'react';
import { FC, forwardRef, useMemo } from 'react';
import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso';
import { motion } from 'framer-motion';
@@ -7,15 +7,15 @@ import { showPreviewModal } from '@/components/Movie/Preview';
import filterUnknownMovies from '@/lib/filterUnknownMovies';
interface Props {
type?: ShowType;
pages: Array<MovieDBResponse>;
hasNextPage?: boolean;
customScrollParent?: HTMLElement;
fetchNextPage?: () => void;
onPreviewClose?: () => void;
type?: ShowType;
customScrollParent?: HTMLElement;
}
const item = {
const container = {
hidden: { y: -20, opacity: 0 },
visible: {
y: 0,
@@ -23,31 +23,28 @@ const item = {
}
};
const components: VirtuosoGridProps<
Movie,
{ shows: Movie[]; initial: boolean; onClick: (movie: Movie) => void }
>['components'] = {
const components: VirtuosoGridProps<Movie, { shows: Movie[]; onClick: (movie: Movie) => void }>['components'] = {
List: forwardRef(function List({ context, ...props }, ref) {
return (
<motion.div
{...props}
variants={container}
initial='hidden'
animate='visible'
className='flex gap-2 flex-wrap justify-center grow empty:hidden'
ref={ref}
/>
);
}),
Item: ({ context, 'data-index': index }) => {
const { shows, onClick } = context || {};
const movie = shows?.[index];
return (
<motion.div
variants={item}
initial='hidden'
animate='visible'
transition={context?.initial ? { delay: 0.15 * index } : undefined}
className='xs:w-[300px] xs:h-[450px] w-full h-full shrink-0'
>
<Card movie={movie} onClick={() => onClick?.(movie!)} />
</motion.div>
);
return <Card movie={movie} onClick={() => onClick?.(movie!)} />;
}
};
const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, onPreviewClose, type = 'movie', customScrollParent }) => {
const initial = useRef(true);
const shows = useMemo(
() =>
pages?.reduce((shows, page) => {
@@ -61,13 +58,11 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, onPreviewClose, ty
const context = {
shows,
initial: initial.current,
onClick: (movie: Movie) => showPreviewModal({ movie, onClose: onPreviewClose, type })
};
const handleFetchMore = () => {
if (!hasNextPage) return;
initial.current = false;
fetchNextPage?.();
};
@@ -75,10 +70,8 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, onPreviewClose, ty
<>
<VirtuosoGrid
useWindowScroll
listClassName='flex gap-2 flex-wrap justify-center grow empty:hidden'
customScrollParent={customScrollParent}
totalCount={shows.length}
initialItemCount={20}
overscan={4}
endReached={handleFetchMore}
data={shows}
+1 -1
View File
@@ -110,7 +110,7 @@ const DialogContent = React.forwardRef<
ref={handleRef}
{...props}
className={cn(
'absolute top-[20vh] max-w-[1000px] w-[calc(100%-24px)] left-[50%] rounded-xl translate-x-[-50%] gap-4 shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=open]:slide-in-from-left-1/2 bg-background',
'absolute top-[20vh] max-w-[930px] w-[calc(100%-24px)] left-[50%] rounded-xl translate-x-[-50%] gap-4 shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=open]:slide-in-from-left-1/2 bg-background',
className
)}
>
+1 -1
View File
@@ -63,7 +63,7 @@ const DropdownMenuContent = React.forwardRef<
ref={ref}
sideOffset={sideOffset}
className={cn(
'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
className
)}
{...props}