feat: added favorites page
This commit is contained in:
1 parent
0cb860d0a0
commit
89e76f5df6
27 files changed
+412
-116
No files matched your search
@@ -25,11 +25,12 @@ const Header: FC = () => {
|
||||
</Button>
|
||||
</div>
|
||||
<Tabs value={path} className='flex-grow mt-2'>
|
||||
<TabsList className='grid w-full grid-cols-3'>
|
||||
<TabsList className='grid w-full grid-cols-4'>
|
||||
{[
|
||||
['/', 'Random'],
|
||||
['/top', 'Top'],
|
||||
['/search', 'Search']
|
||||
['/search', 'Search'],
|
||||
['/favorites', 'Favorites']
|
||||
].map(([path, label]) => (
|
||||
<Link href={path} className='w-full' key={path}>
|
||||
<TabsTrigger className='w-full' value={path}>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { FC } from 'react';
|
||||
import { Star } from 'lucide-react';
|
||||
|
||||
import Poster from '@/components/Movie/components/Poster';
|
||||
import Rating from '@/components/Movie/components/Rating';
|
||||
import Title from '@/components/Movie/components/Title';
|
||||
|
||||
interface Props {
|
||||
@@ -23,12 +24,9 @@ const Card: FC<Props> = ({ movie, className }) => {
|
||||
<span className='flex justify-end text-lg font-semibold'>{new Date(movie.release_date).getFullYear()}</span>
|
||||
)}
|
||||
</div>
|
||||
<div className='flex w-full justify-end items-center gap-1 mt-[-8px]'>
|
||||
<Star size={17} />
|
||||
<span className='text-lg font-semibold'>{movie.vote_average}</span>
|
||||
</div>
|
||||
<Rating movie={movie} />
|
||||
</div>
|
||||
<div className='flex justify-center relative mt-1'>
|
||||
<div className='flex justify-center relative mt-1 grow'>
|
||||
<Poster title={movie.title} width={300} height={450} size={100} poster={movie.poster_path} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,11 +4,12 @@ import { InfiniteData, useInfiniteQuery, UseInfiniteQueryResult } from '@tanstac
|
||||
import Card from '@/components/Movie/Card';
|
||||
import Preview from '@/components/Movie/Preview';
|
||||
import { Dialog, DialogContent } from '@/components/ui/dialog';
|
||||
import filterUnknownMovies from '@/lib/filterUnknownMovies';
|
||||
|
||||
interface Props {
|
||||
pages: Array<MovieDBResponse>;
|
||||
hasNextPage: boolean;
|
||||
fetchNextPage: () => void;
|
||||
hasNextPage?: boolean;
|
||||
fetchNextPage?: () => void;
|
||||
}
|
||||
|
||||
const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
||||
@@ -22,7 +23,7 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
||||
([{ isIntersecting }]) => {
|
||||
if (!isIntersecting) return;
|
||||
|
||||
fetchNextPage();
|
||||
fetchNextPage?.();
|
||||
},
|
||||
{
|
||||
threshold: 1
|
||||
@@ -36,17 +37,17 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<ul className='flex gap-3 flex-wrap justify-between'>
|
||||
<ul className='flex gap-3 flex-wrap justify-between grow'>
|
||||
{pages.map((page) => (
|
||||
<Fragment key={page.page}>
|
||||
{page.results?.map((movie, index, array) => (
|
||||
{filterUnknownMovies(page.results)?.map((movie, index, array) => (
|
||||
<li
|
||||
key={movie.id}
|
||||
className='flex grow basis-[300px] cursor-pointer'
|
||||
onClick={() => setMovie(movie)}
|
||||
ref={array.length / 2 !== index ? undefined : (element) => setLoader(element!)}
|
||||
>
|
||||
<Card movie={movie} className='grow' />
|
||||
<Card movie={movie} className='grow flex flex-col' />
|
||||
</li>
|
||||
))}
|
||||
</Fragment>
|
||||
@@ -56,7 +57,15 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
||||
{movie && (
|
||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setMovie(null)}>
|
||||
<DialogContent className='block p-0'>
|
||||
<Preview movie={movie} className='border-none' />
|
||||
<Preview
|
||||
key={movie.id}
|
||||
movie={movie}
|
||||
className='border-none'
|
||||
onPersonClick={() => {
|
||||
setMovie(null);
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}}
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
|
||||
@@ -1,86 +1,120 @@
|
||||
import { FC } from 'react';
|
||||
import { Star, User2 } from 'lucide-react';
|
||||
import { FC, useState } from 'react';
|
||||
import { Play, Star, User2 } from 'lucide-react';
|
||||
import Image from 'next/image';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import useFavorites from '@/app/(site)/favorites/useFavorites';
|
||||
import useCredits from '@/app/(site)/useCredits';
|
||||
import useTrailer from '@/app/(site)/useTrailer';
|
||||
import Poster from '@/components/Movie/components/Poster';
|
||||
import Rating from '@/components/Movie/components/Rating';
|
||||
import Title from '@/components/Movie/components/Title';
|
||||
import { CardTitle } from '@/components/ui/card';
|
||||
import { Dialog, DialogContent } from '@/components/ui/dialog';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
className?: string;
|
||||
onPersonClick?: (id: string) => void;
|
||||
}
|
||||
|
||||
const Preview: FC<Props> = ({ movie, className }) => {
|
||||
const Preview: FC<Props> = ({ movie, className, onPersonClick }) => {
|
||||
const { data: credits } = useCredits({ movieId: movie?.id });
|
||||
const { data: trailer } = useTrailer({ movieId: movie?.id });
|
||||
|
||||
const [isShowTrailer, setIsShowTrailer] = useState(false);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
if (!movie) return null;
|
||||
|
||||
return (
|
||||
<div className={`p-3 rounded-lg border bg-card text-card-foreground shadow-sm ${className}`}>
|
||||
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3 overflow-hidden'>
|
||||
<Poster
|
||||
title={movie.title}
|
||||
width={300}
|
||||
height={450}
|
||||
size={100}
|
||||
poster={movie.poster_path}
|
||||
className='max-w-[300px]'
|
||||
/>
|
||||
<div className='flex flex-col grow lg:max-w-[calc(100%-(300px+0.75rem))]'>
|
||||
<div className='flex'>
|
||||
<div className='flex flex-row flex-wrap w-full text-lg font-semibold'>
|
||||
<span className='flex w-full items-center'>
|
||||
<span className='mr-2 w-full'>
|
||||
<Title title={movie.title} />
|
||||
</span>
|
||||
{movie.release_date && <span className='ml-auto'>{new Date(movie.release_date).getFullYear()}</span>}
|
||||
</span>
|
||||
<span className='flex items-center ml-auto gap-1 mt-[-8px]'>
|
||||
<Star size={18} />
|
||||
<span>{movie.vote_average}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<Separator className='my-4' />
|
||||
<div className='flex flex-col items-start grow justify-between'>
|
||||
<p className='leading-7'>{movie.overview}</p>
|
||||
{Boolean(credits?.length) && (
|
||||
<div className='overflow-auto max-w-[100%] mt-4'>
|
||||
<ul className='flex gap-2'>
|
||||
{credits?.map((actor) => (
|
||||
<li
|
||||
key={`${actor.id}_${actor.cast_id}`}
|
||||
title={actor.name}
|
||||
className='p-2 rounded-lg border bg-card text-card-foreground shadow-sm self-end max-w-[150px] w-full shrink-0'
|
||||
>
|
||||
<div className='rounded-lg overflow-hidden'>
|
||||
{actor.profile_path ? (
|
||||
<Image
|
||||
unoptimized
|
||||
height={225}
|
||||
width={150}
|
||||
src={`https://image.tmdb.org/t/p/w500/${actor.profile_path}`}
|
||||
alt={actor.name}
|
||||
/>
|
||||
) : (
|
||||
<div className='w-[132px] h-[198px] flex items-center justify-center rounded-lg border'>
|
||||
<User2 size={120} strokeWidth={1} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className='pt-2 overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.name}</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<>
|
||||
<div className={`p-3 rounded-xl border bg-card text-card-foreground shadow-sm ${className}`}>
|
||||
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3 overflow-hidden'>
|
||||
<div className='relative shrink-0'>
|
||||
<Poster title={movie.title} width={300} height={350} size={100} poster={movie.poster_path} />
|
||||
{trailer && (
|
||||
<div
|
||||
onClick={() => setIsShowTrailer(true)}
|
||||
title='Play trailer'
|
||||
className='absolute w-full h-full left-0 top-0 bg-black cursor-pointer overflow-hidden rounded-lg transition-opacity opacity-0 hover:opacity-70 flex items-center justify-center'
|
||||
>
|
||||
<Play size={100} className='fill-white' />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className='flex flex-col grow'>
|
||||
<div className='flex'>
|
||||
<div className='flex flex-row flex-wrap w-full text-lg font-semibold'>
|
||||
<span className='flex w-full items-center'>
|
||||
<span className='mr-2 w-full'>
|
||||
<Title title={movie.title} />
|
||||
</span>
|
||||
{movie.release_date && <span className='ml-auto'>{new Date(movie.release_date).getFullYear()}</span>}
|
||||
</span>
|
||||
<Rating movie={movie} />
|
||||
</div>
|
||||
</div>
|
||||
<Separator className='my-2' />
|
||||
<div className='flex flex-col items-start grow justify-between'>
|
||||
<p className='leading-7'>{movie.overview}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{Boolean(credits?.length) && (
|
||||
<div className='overflow-auto max-w-[100%] py-3 mb-[-0.75rem]'>
|
||||
<ul className='flex gap-3'>
|
||||
{credits?.map((actor) => (
|
||||
<li
|
||||
key={`${actor.id}_${actor.cast_id}`}
|
||||
title={actor.name}
|
||||
onClick={() => {
|
||||
router.push(`/top?starring=${actor.id}`);
|
||||
onPersonClick?.(actor.id.toString());
|
||||
}}
|
||||
className='p-2 rounded-lg border bg-card text-card-foreground self-end max-w-[150px] w-full shrink-0 cursor-pointer transition-shadow hover:shadow-lg'
|
||||
>
|
||||
{Boolean(actor.character) && (
|
||||
<p className='pb-2 overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.character}</p>
|
||||
)}
|
||||
<div className='rounded-md overflow-hidden'>
|
||||
{actor.profile_path ? (
|
||||
<Image
|
||||
unoptimized
|
||||
height={225}
|
||||
width={150}
|
||||
src={`https://image.tmdb.org/t/p/w500/${actor.profile_path}`}
|
||||
alt={actor.name}
|
||||
/>
|
||||
) : (
|
||||
<div className='w-[132px] h-[198px] flex items-center justify-center rounded-lg border'>
|
||||
<User2 size={120} strokeWidth={1} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className='pt-2 overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.name}</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{trailer && isShowTrailer && (
|
||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setIsShowTrailer(false)}>
|
||||
<DialogContent className='block p-0 min-h-[400px] aspect-w-16 aspect-h-9'>
|
||||
<iframe
|
||||
allow='autoplay'
|
||||
className='border-none rounded-lg'
|
||||
width='100%'
|
||||
height='100%'
|
||||
src={`//www.youtube.com/embed/${trailer?.key}?autoplay=1`}
|
||||
allowFullScreen
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ const Poster: FC<Props> = ({ title, poster, width, height, size = 250, className
|
||||
alt={title}
|
||||
/>
|
||||
) : (
|
||||
<div className={`h-[${height}px] w-full flex items-center justify-center rounded-lg border`}>
|
||||
<div className={`h-[${height}px] w-full flex items-center justify-center rounded-lg border grow`}>
|
||||
<ImageOff size={size} strokeWidth={1} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { FC } from 'react';
|
||||
import { Heart, Star } from 'lucide-react';
|
||||
|
||||
import useFavorites, { useFavoritesMutation } from '@/app/(site)/favorites/useFavorites';
|
||||
|
||||
interface Props {
|
||||
movie: Movie;
|
||||
}
|
||||
|
||||
const Rating: FC<Props> = ({ movie }) => {
|
||||
const { map } = useFavorites();
|
||||
const { add, remove } = useFavoritesMutation();
|
||||
|
||||
const isFavorite = map.has(movie.id);
|
||||
|
||||
return (
|
||||
<span className='select-none flex w-full items-center ml-auto gap-1 mt-[-8px] justify-between'>
|
||||
<span
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
|
||||
isFavorite ? remove(movie.id) : add(movie);
|
||||
}}
|
||||
className='z-[2] cursor-pointer'
|
||||
title={isFavorite ? 'Remove from favorites' : 'Add to favorite'}
|
||||
>
|
||||
<Heart className={isFavorite ? 'fill-accent-foreground' : ''} size={18} />
|
||||
</span>
|
||||
<span className='flex items-center'>
|
||||
<Star size={18} className='fill-accent-foreground mr-1' />
|
||||
<span className='font-semibold'>{movie.vote_average?.toFixed(1)}</span>
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
export default Rating;
|
||||
@@ -26,7 +26,7 @@ const Title: FC<Props> = ({ title }) => {
|
||||
isScrollableTitle && setIsScrollableTitle(isScrollableTitle);
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
{title}
|
||||
</div>
|
||||
</Marquee>
|
||||
);
|
||||
|
||||
@@ -44,7 +44,7 @@ const DialogContent = React.forwardRef<
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<DialogPrimitive.Close type='button' autoFocus={false} className='absolute w-full block h-[20vh] outline-0' />
|
||||
<div className='absolute w-full block h-[20vh] pointer-events-none' />
|
||||
</DialogPrimitive.Content>
|
||||
</DialogOverlay>
|
||||
</DialogPortal>
|
||||
|
||||
Reference in new issue
Block a user