feat: added favorites page
This commit is contained in:
1 parent
0cb860d0a0
commit
89e76f5df6
27 files changed
+412
-116
No files matched your search
@@ -12,6 +12,13 @@ const API = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
trailers({ movieId }: { movieId: number }): Promise<Trailer[]> {
|
||||||
|
return client.get('/trailer', {
|
||||||
|
params: {
|
||||||
|
movieId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
random({ filters }: { filters: Partial<Filters> }): Promise<Movie[]> {
|
random({ filters }: { filters: Partial<Filters> }): Promise<Movie[]> {
|
||||||
return client.get('/random', {
|
return client.get('/random', {
|
||||||
params: {
|
params: {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { RefreshCcwDot } from 'lucide-react';
|
import { ArrowLeft, ArrowRight } from 'lucide-react';
|
||||||
|
|
||||||
import Movie from '@/components/Movie/Preview';
|
import Movie from '@/components/Movie/Preview';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -8,14 +8,21 @@ import { Button } from '@/components/ui/button';
|
|||||||
import useRandomMovie from './useRandomMovie';
|
import useRandomMovie from './useRandomMovie';
|
||||||
|
|
||||||
export default function Container() {
|
export default function Container() {
|
||||||
const { movie, next } = useRandomMovie();
|
const { movie, next, previous, hasPrevious } = useRandomMovie();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button className='w-full mb-2 p-2' onClick={next} title='Next movie'>
|
<div className='gap-2 flex'>
|
||||||
<RefreshCcwDot size={24} strokeWidth={1} />
|
<Button className='mb-2 p-2' onClick={previous} disabled={!hasPrevious} title='Previous movie'>
|
||||||
</Button>
|
<ArrowLeft size={24} strokeWidth={1} />
|
||||||
<Movie movie={movie} />
|
</Button>
|
||||||
|
<Button className='w-full mb-2 p-2 grow' onClick={next} title='Next movie'>
|
||||||
|
<ArrowRight size={24} strokeWidth={1} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Movie key={movie?.id} movie={movie} />
|
||||||
|
<div className='w-full h-2' />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import useFavorites from '@/app/(site)/favorites/useFavorites';
|
||||||
|
import List from '@/components/Movie/List';
|
||||||
|
|
||||||
|
export default function Container() {
|
||||||
|
const { pages } = useFavorites();
|
||||||
|
|
||||||
|
return <List pages={pages} />;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import Container from './container';
|
||||||
|
|
||||||
|
export default async function Favorites() {
|
||||||
|
return <Container />;
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
||||||
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
|
|
||||||
|
const favoritesAtom = atomWithStorage<Array<MovieDBResponse>>('favorite', [
|
||||||
|
{ page: 1, results: [], total_pages: 1, total_results: 0 }
|
||||||
|
]);
|
||||||
|
const favoritesMapAtom = atom((get) => {
|
||||||
|
const map = new Map();
|
||||||
|
const favorites = get(favoritesAtom);
|
||||||
|
|
||||||
|
favorites[0].results.forEach((movie) => map.set(movie.id, movie));
|
||||||
|
|
||||||
|
return map as Map<number, Movie>;
|
||||||
|
});
|
||||||
|
const useFavorites = () => {
|
||||||
|
return {
|
||||||
|
pages: useAtomValue(favoritesAtom),
|
||||||
|
map: useAtomValue(favoritesMapAtom)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useFavoritesMutation = () => {
|
||||||
|
const setFavorites = useSetAtom(favoritesAtom);
|
||||||
|
const add = (movie: Movie) => {
|
||||||
|
setFavorites((favorites) => {
|
||||||
|
favorites[0].results = [movie, ...favorites[0].results];
|
||||||
|
favorites[0].total_results = favorites[0].results.length;
|
||||||
|
return [...favorites];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const remove = (movieId: number) => {
|
||||||
|
setFavorites((favorites) => {
|
||||||
|
favorites[0].results = favorites[0].results.filter((movie) => movie.id !== movieId);
|
||||||
|
favorites[0].total_results = favorites[0].results.length;
|
||||||
|
return [...favorites];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
add,
|
||||||
|
remove
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useFavorites;
|
||||||
+10
-1
@@ -1,16 +1,25 @@
|
|||||||
import client from '@/network';
|
import client from '@/network';
|
||||||
|
|
||||||
const API = {
|
const API = {
|
||||||
top({ page }: { page: string }): Promise<MovieDBResponse> {
|
top({ page, starring }: { page: string; starring: string | null }): Promise<MovieDBResponse> {
|
||||||
return client.get('/discover', {
|
return client.get('/discover', {
|
||||||
params: {
|
params: {
|
||||||
page,
|
page,
|
||||||
|
with_cast: starring,
|
||||||
|
with_people: starring,
|
||||||
sort_by: 'vote_average.desc',
|
sort_by: 'vote_average.desc',
|
||||||
'vote_count.gte': 300,
|
'vote_count.gte': 300,
|
||||||
'vote_average.lte': 10,
|
'vote_average.lte': 10,
|
||||||
'vote_average.gte': 0
|
'vote_average.gte': 0
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
person({ id }: { id: string }): Promise<Person> {
|
||||||
|
return client.get('/person', {
|
||||||
|
params: {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,25 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useSearchParams } from 'next/navigation';
|
||||||
|
|
||||||
|
import usePerson from '@/app/(site)/top/usePerson';
|
||||||
import List from '@/components/Movie/List';
|
import List from '@/components/Movie/List';
|
||||||
|
|
||||||
import useTop from './useTop';
|
import useTop from './useTop';
|
||||||
|
|
||||||
export default function Container() {
|
export default function Container() {
|
||||||
const { data: top, hasNextPage, fetchNextPage } = useTop();
|
const starring = useSearchParams().get('starring');
|
||||||
|
const { data: person } = usePerson({ id: starring });
|
||||||
|
const { data: top, hasNextPage, fetchNextPage } = useTop({ starring });
|
||||||
|
|
||||||
return <List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />;
|
return (
|
||||||
|
<>
|
||||||
|
{Boolean(person) && (
|
||||||
|
<span className='inline-flex w-full h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground mb-2'>
|
||||||
|
Starring: {person?.name}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -3,3 +3,5 @@ import Container from './container';
|
|||||||
export default function Top() {
|
export default function Top() {
|
||||||
return <Container />;
|
return <Container />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const revalidate = 3600;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import API from './api';
|
||||||
|
|
||||||
|
const usePerson = ({ id }: { id: string | null }) => {
|
||||||
|
return useQuery({ enabled: Boolean(id), queryKey: ['person', id], queryFn: () => API.person({ id: id! }) });
|
||||||
|
};
|
||||||
|
|
||||||
|
export default usePerson;
|
||||||
@@ -5,12 +5,12 @@ import { useSearchParams } from 'next/navigation';
|
|||||||
|
|
||||||
import API from './api';
|
import API from './api';
|
||||||
|
|
||||||
const useTop = () => {
|
const useTop = ({ starring }: { starring: string | null }) => {
|
||||||
const page = useSearchParams().get('page');
|
const page = useSearchParams().get('page');
|
||||||
|
|
||||||
return useInfiniteQuery({
|
return useInfiniteQuery({
|
||||||
queryKey: ['top'],
|
queryKey: ['top', starring],
|
||||||
queryFn: ({ pageParam: page }) => API.top({ page }),
|
queryFn: ({ pageParam: page }) => API.top({ page, starring }),
|
||||||
suspense: true,
|
suspense: true,
|
||||||
getNextPageParam({ page, total_pages }) {
|
getNextPageParam({ page, total_pages }) {
|
||||||
if (page === total_pages) return undefined;
|
if (page === total_pages) return undefined;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
import useFilters from '@/app/(site)/useFilters';
|
import useFilters from '@/app/(site)/useFilters';
|
||||||
|
import filterUnknownMovies from '@/lib/filterUnknownMovies';
|
||||||
|
|
||||||
import API from './api';
|
import API from './api';
|
||||||
|
|
||||||
@@ -20,6 +21,9 @@ const useRandomMovie = () => {
|
|||||||
queryKey: ['random-movie', filters],
|
queryKey: ['random-movie', filters],
|
||||||
queryFn: () => API.random({ filters }),
|
queryFn: () => API.random({ filters }),
|
||||||
suspense: true,
|
suspense: true,
|
||||||
|
select(movies) {
|
||||||
|
return filterUnknownMovies(movies);
|
||||||
|
},
|
||||||
structuralSharing(current, next) {
|
structuralSharing(current, next) {
|
||||||
const uniqueIds: Record<string, number> = {};
|
const uniqueIds: Record<string, number> = {};
|
||||||
|
|
||||||
@@ -38,6 +42,12 @@ const useRandomMovie = () => {
|
|||||||
setIndex(indexByFilter || 0);
|
setIndex(indexByFilter || 0);
|
||||||
}, [indexByFilter]);
|
}, [indexByFilter]);
|
||||||
|
|
||||||
|
const previous = () => {
|
||||||
|
if (!index) return;
|
||||||
|
|
||||||
|
setIndex((index) => index - 1);
|
||||||
|
};
|
||||||
|
|
||||||
const next = () => {
|
const next = () => {
|
||||||
if ((index && index % UPDATE_RATE === 0) || movies!.length < UPDATE_RATE) {
|
if ((index && index % UPDATE_RATE === 0) || movies!.length < UPDATE_RATE) {
|
||||||
refetch();
|
refetch();
|
||||||
@@ -51,7 +61,9 @@ const useRandomMovie = () => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
movie: movies?.[index],
|
movie: movies?.[index],
|
||||||
next
|
hasPrevious: index > 0,
|
||||||
|
next,
|
||||||
|
previous
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import API from '@/app/(site)/api';
|
||||||
|
|
||||||
|
const useTrailer = ({ movieId }: { movieId?: number }) => {
|
||||||
|
return useQuery({
|
||||||
|
enabled: Boolean(movieId),
|
||||||
|
queryKey: ['trailers', movieId],
|
||||||
|
queryFn: () => API.trailers({ movieId: movieId! }),
|
||||||
|
select(trailers) {
|
||||||
|
const trailer = trailers[0];
|
||||||
|
return trailer?.site === 'YouTube' ? trailer : null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useTrailer;
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
|
||||||
|
import server from '@/network/server';
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const params = Object.fromEntries(new URL(request.url).searchParams.entries());
|
||||||
|
const response = await server.get(`/person/${params.id}`);
|
||||||
|
|
||||||
|
return NextResponse.json(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const revalidate = 3600 * 24;
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
|
||||||
|
import server from '@/network/server';
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const params = Object.fromEntries(new URL(request.url).searchParams.entries());
|
||||||
|
const response: { id: number; results: Trailer[] } = await server.get(`/movie/${params.movieId}/videos`, {
|
||||||
|
params: {
|
||||||
|
language: 'en-US'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json(response?.results || []);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const revalidate = 3600 * 24;
|
||||||
@@ -25,11 +25,12 @@ const Header: FC = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<Tabs value={path} className='flex-grow mt-2'>
|
<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'],
|
['/', 'Random'],
|
||||||
['/top', 'Top'],
|
['/top', 'Top'],
|
||||||
['/search', 'Search']
|
['/search', 'Search'],
|
||||||
|
['/favorites', 'Favorites']
|
||||||
].map(([path, label]) => (
|
].map(([path, label]) => (
|
||||||
<Link href={path} className='w-full' key={path}>
|
<Link href={path} className='w-full' key={path}>
|
||||||
<TabsTrigger className='w-full' value={path}>
|
<TabsTrigger className='w-full' value={path}>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { FC } from 'react';
|
|||||||
import { Star } from 'lucide-react';
|
import { Star } from 'lucide-react';
|
||||||
|
|
||||||
import Poster from '@/components/Movie/components/Poster';
|
import Poster from '@/components/Movie/components/Poster';
|
||||||
|
import Rating from '@/components/Movie/components/Rating';
|
||||||
import Title from '@/components/Movie/components/Title';
|
import Title from '@/components/Movie/components/Title';
|
||||||
|
|
||||||
interface Props {
|
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>
|
<span className='flex justify-end text-lg font-semibold'>{new Date(movie.release_date).getFullYear()}</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className='flex w-full justify-end items-center gap-1 mt-[-8px]'>
|
<Rating movie={movie} />
|
||||||
<Star size={17} />
|
|
||||||
<span className='text-lg font-semibold'>{movie.vote_average}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</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} />
|
<Poster title={movie.title} width={300} height={450} size={100} poster={movie.poster_path} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import { InfiniteData, useInfiniteQuery, UseInfiniteQueryResult } from '@tanstac
|
|||||||
import Card from '@/components/Movie/Card';
|
import Card from '@/components/Movie/Card';
|
||||||
import Preview from '@/components/Movie/Preview';
|
import Preview from '@/components/Movie/Preview';
|
||||||
import { Dialog, DialogContent } from '@/components/ui/dialog';
|
import { Dialog, DialogContent } from '@/components/ui/dialog';
|
||||||
|
import filterUnknownMovies from '@/lib/filterUnknownMovies';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
pages: Array<MovieDBResponse>;
|
pages: Array<MovieDBResponse>;
|
||||||
hasNextPage: boolean;
|
hasNextPage?: boolean;
|
||||||
fetchNextPage: () => void;
|
fetchNextPage?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
||||||
@@ -22,7 +23,7 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
|||||||
([{ isIntersecting }]) => {
|
([{ isIntersecting }]) => {
|
||||||
if (!isIntersecting) return;
|
if (!isIntersecting) return;
|
||||||
|
|
||||||
fetchNextPage();
|
fetchNextPage?.();
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
threshold: 1
|
threshold: 1
|
||||||
@@ -36,17 +37,17 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ul className='flex gap-3 flex-wrap justify-between'>
|
<ul className='flex gap-3 flex-wrap justify-between grow'>
|
||||||
{pages.map((page) => (
|
{pages.map((page) => (
|
||||||
<Fragment key={page.page}>
|
<Fragment key={page.page}>
|
||||||
{page.results?.map((movie, index, array) => (
|
{filterUnknownMovies(page.results)?.map((movie, index, array) => (
|
||||||
<li
|
<li
|
||||||
key={movie.id}
|
key={movie.id}
|
||||||
className='flex grow basis-[300px] cursor-pointer'
|
className='flex grow basis-[300px] cursor-pointer'
|
||||||
onClick={() => setMovie(movie)}
|
onClick={() => setMovie(movie)}
|
||||||
ref={array.length / 2 !== index ? undefined : (element) => setLoader(element!)}
|
ref={array.length / 2 !== index ? undefined : (element) => setLoader(element!)}
|
||||||
>
|
>
|
||||||
<Card movie={movie} className='grow' />
|
<Card movie={movie} className='grow flex flex-col' />
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
@@ -56,7 +57,15 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
|||||||
{movie && (
|
{movie && (
|
||||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setMovie(null)}>
|
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setMovie(null)}>
|
||||||
<DialogContent className='block p-0'>
|
<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>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,86 +1,120 @@
|
|||||||
import { FC } from 'react';
|
import { FC, useState } from 'react';
|
||||||
import { Star, User2 } from 'lucide-react';
|
import { Play, Star, User2 } from 'lucide-react';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
|
import useFavorites from '@/app/(site)/favorites/useFavorites';
|
||||||
import useCredits from '@/app/(site)/useCredits';
|
import useCredits from '@/app/(site)/useCredits';
|
||||||
|
import useTrailer from '@/app/(site)/useTrailer';
|
||||||
import Poster from '@/components/Movie/components/Poster';
|
import Poster from '@/components/Movie/components/Poster';
|
||||||
|
import Rating from '@/components/Movie/components/Rating';
|
||||||
import Title from '@/components/Movie/components/Title';
|
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';
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
movie?: Movie;
|
movie?: Movie;
|
||||||
className?: string;
|
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: credits } = useCredits({ movieId: movie?.id });
|
||||||
|
const { data: trailer } = useTrailer({ movieId: movie?.id });
|
||||||
|
|
||||||
|
const [isShowTrailer, setIsShowTrailer] = useState(false);
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
if (!movie) return null;
|
if (!movie) return null;
|
||||||
|
|
||||||
return (
|
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'>
|
<div className={`p-3 rounded-xl border bg-card text-card-foreground shadow-sm ${className}`}>
|
||||||
<Poster
|
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3 overflow-hidden'>
|
||||||
title={movie.title}
|
<div className='relative shrink-0'>
|
||||||
width={300}
|
<Poster title={movie.title} width={300} height={350} size={100} poster={movie.poster_path} />
|
||||||
height={450}
|
{trailer && (
|
||||||
size={100}
|
<div
|
||||||
poster={movie.poster_path}
|
onClick={() => setIsShowTrailer(true)}
|
||||||
className='max-w-[300px]'
|
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'
|
||||||
<div className='flex flex-col grow lg:max-w-[calc(100%-(300px+0.75rem))]'>
|
>
|
||||||
<div className='flex'>
|
<Play size={100} className='fill-white' />
|
||||||
<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>
|
</div>
|
||||||
)}
|
)}
|
||||||
</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>
|
</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>
|
||||||
</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}
|
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} />
|
<ImageOff size={size} strokeWidth={1} />
|
||||||
</div>
|
</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);
|
isScrollableTitle && setIsScrollableTitle(isScrollableTitle);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{title}
|
{title}
|
||||||
</div>
|
</div>
|
||||||
</Marquee>
|
</Marquee>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ const DialogContent = React.forwardRef<
|
|||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{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>
|
</DialogPrimitive.Content>
|
||||||
</DialogOverlay>
|
</DialogOverlay>
|
||||||
</DialogPortal>
|
</DialogPortal>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
const filterUnknownMovies = (movies: Movie[]): Movie[] => {
|
||||||
|
return movies?.filter((movie) => movie?.vote_count && movie?.release_date) || [];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default filterUnknownMovies;
|
||||||
Generated
+17
@@ -44,6 +44,7 @@
|
|||||||
"typescript": "5.1.6"
|
"typescript": "5.1.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@tailwindcss/aspect-ratio": "^0.4.2",
|
||||||
"@types/js-cookie": "^3.0.3",
|
"@types/js-cookie": "^3.0.3",
|
||||||
"@types/node": "20.4.4",
|
"@types/node": "20.4.4",
|
||||||
"@types/react": "18.2.15",
|
"@types/react": "18.2.15",
|
||||||
@@ -1362,6 +1363,15 @@
|
|||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@tailwindcss/aspect-ratio": {
|
||||||
|
"version": "0.4.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tailwindcss/aspect-ratio/-/aspect-ratio-0.4.2.tgz",
|
||||||
|
"integrity": "sha512-8QPrypskfBa7QIMuKHg2TA7BqES6vhBrDLOv8Unb6FcFyd3TjKbc6lcmb9UPQHxfl24sXoJ41ux/H7qQQvfaSQ==",
|
||||||
|
"dev": true,
|
||||||
|
"peerDependencies": {
|
||||||
|
"tailwindcss": ">=2.0.0 || >=3.0.0 || >=3.0.0-alpha.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@tanstack/query-core": {
|
"node_modules/@tanstack/query-core": {
|
||||||
"version": "5.0.0-alpha.70",
|
"version": "5.0.0-alpha.70",
|
||||||
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.0.0-alpha.70.tgz",
|
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.0.0-alpha.70.tgz",
|
||||||
@@ -6620,6 +6630,13 @@
|
|||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@tailwindcss/aspect-ratio": {
|
||||||
|
"version": "0.4.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tailwindcss/aspect-ratio/-/aspect-ratio-0.4.2.tgz",
|
||||||
|
"integrity": "sha512-8QPrypskfBa7QIMuKHg2TA7BqES6vhBrDLOv8Unb6FcFyd3TjKbc6lcmb9UPQHxfl24sXoJ41ux/H7qQQvfaSQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {}
|
||||||
|
},
|
||||||
"@tanstack/query-core": {
|
"@tanstack/query-core": {
|
||||||
"version": "5.0.0-alpha.70",
|
"version": "5.0.0-alpha.70",
|
||||||
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.0.0-alpha.70.tgz",
|
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.0.0-alpha.70.tgz",
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
"typescript": "5.1.6"
|
"typescript": "5.1.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@tailwindcss/aspect-ratio": "^0.4.2",
|
||||||
"@types/js-cookie": "^3.0.3",
|
"@types/js-cookie": "^3.0.3",
|
||||||
"@types/node": "20.4.4",
|
"@types/node": "20.4.4",
|
||||||
"@types/react": "18.2.15",
|
"@types/react": "18.2.15",
|
||||||
|
|||||||
+23
-25
@@ -1,19 +1,14 @@
|
|||||||
/** @type {import('tailwindcss').Config} */
|
/** @type {import('tailwindcss').Config} */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
darkMode: ['class'],
|
darkMode: ['class'],
|
||||||
content: [
|
content: ['./pages/**/*.{ts,tsx}', './components/**/*.{ts,tsx}', './app/**/*.{ts,tsx}', './src/**/*.{ts,tsx}'],
|
||||||
'./pages/**/*.{ts,tsx}',
|
|
||||||
'./components/**/*.{ts,tsx}',
|
|
||||||
'./app/**/*.{ts,tsx}',
|
|
||||||
'./src/**/*.{ts,tsx}',
|
|
||||||
],
|
|
||||||
theme: {
|
theme: {
|
||||||
container: {
|
container: {
|
||||||
center: true,
|
center: true,
|
||||||
padding: '2rem',
|
padding: '2rem',
|
||||||
screens: {
|
screens: {
|
||||||
'2xl': '1400px',
|
'2xl': '1400px'
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
extend: {
|
extend: {
|
||||||
colors: {
|
colors: {
|
||||||
@@ -24,53 +19,56 @@ module.exports = {
|
|||||||
foreground: 'hsl(var(--foreground))',
|
foreground: 'hsl(var(--foreground))',
|
||||||
primary: {
|
primary: {
|
||||||
DEFAULT: 'hsl(var(--primary))',
|
DEFAULT: 'hsl(var(--primary))',
|
||||||
foreground: 'hsl(var(--primary-foreground))',
|
foreground: 'hsl(var(--primary-foreground))'
|
||||||
},
|
},
|
||||||
secondary: {
|
secondary: {
|
||||||
DEFAULT: 'hsl(var(--secondary))',
|
DEFAULT: 'hsl(var(--secondary))',
|
||||||
foreground: 'hsl(var(--secondary-foreground))',
|
foreground: 'hsl(var(--secondary-foreground))'
|
||||||
},
|
},
|
||||||
destructive: {
|
destructive: {
|
||||||
DEFAULT: 'hsl(var(--destructive))',
|
DEFAULT: 'hsl(var(--destructive))',
|
||||||
foreground: 'hsl(var(--destructive-foreground))',
|
foreground: 'hsl(var(--destructive-foreground))'
|
||||||
},
|
},
|
||||||
muted: {
|
muted: {
|
||||||
DEFAULT: 'hsl(var(--muted))',
|
DEFAULT: 'hsl(var(--muted))',
|
||||||
foreground: 'hsl(var(--muted-foreground))',
|
foreground: 'hsl(var(--muted-foreground))'
|
||||||
},
|
},
|
||||||
accent: {
|
accent: {
|
||||||
DEFAULT: 'hsl(var(--accent))',
|
DEFAULT: 'hsl(var(--accent))',
|
||||||
foreground: 'hsl(var(--accent-foreground))',
|
foreground: 'hsl(var(--accent-foreground))'
|
||||||
},
|
},
|
||||||
popover: {
|
popover: {
|
||||||
DEFAULT: 'hsl(var(--popover))',
|
DEFAULT: 'hsl(var(--popover))',
|
||||||
foreground: 'hsl(var(--popover-foreground))',
|
foreground: 'hsl(var(--popover-foreground))'
|
||||||
},
|
},
|
||||||
card: {
|
card: {
|
||||||
DEFAULT: 'hsl(var(--card))',
|
DEFAULT: 'hsl(var(--card))',
|
||||||
foreground: 'hsl(var(--card-foreground))',
|
foreground: 'hsl(var(--card-foreground))'
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
borderRadius: {
|
borderRadius: {
|
||||||
lg: 'var(--radius)',
|
lg: 'var(--radius)',
|
||||||
md: 'calc(var(--radius) - 2px)',
|
md: 'calc(var(--radius) - 2px)',
|
||||||
sm: 'calc(var(--radius) - 4px)',
|
sm: 'calc(var(--radius) - 4px)'
|
||||||
},
|
},
|
||||||
keyframes: {
|
keyframes: {
|
||||||
'accordion-down': {
|
'accordion-down': {
|
||||||
from: { height: 0 },
|
from: { height: 0 },
|
||||||
to: { height: 'var(--radix-accordion-content-height)' },
|
to: { height: 'var(--radix-accordion-content-height)' }
|
||||||
},
|
},
|
||||||
'accordion-up': {
|
'accordion-up': {
|
||||||
from: { height: 'var(--radix-accordion-content-height)' },
|
from: { height: 'var(--radix-accordion-content-height)' },
|
||||||
to: { height: 0 },
|
to: { height: 0 }
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
animation: {
|
animation: {
|
||||||
'accordion-down': 'accordion-down 0.2s ease-out',
|
'accordion-down': 'accordion-down 0.2s ease-out',
|
||||||
'accordion-up': 'accordion-up 0.2s ease-out',
|
'accordion-up': 'accordion-up 0.2s ease-out'
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
plugins: [require('tailwindcss-animate')],
|
corePlugins: {
|
||||||
}
|
aspectRatio: false
|
||||||
|
},
|
||||||
|
plugins: [require('tailwindcss-animate'), require('@tailwindcss/aspect-ratio')]
|
||||||
|
};
|
||||||
Vendored
+30
@@ -39,6 +39,36 @@ interface Actor {
|
|||||||
order: number;
|
order: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Person {
|
||||||
|
adult: boolean;
|
||||||
|
also_known_as: string[];
|
||||||
|
biography: string;
|
||||||
|
birthday: Date;
|
||||||
|
deathday: null;
|
||||||
|
gender: number;
|
||||||
|
homepage: null;
|
||||||
|
id: number;
|
||||||
|
imdb_id: string;
|
||||||
|
known_for_department: string;
|
||||||
|
name: string;
|
||||||
|
place_of_birth: string;
|
||||||
|
popularity: number;
|
||||||
|
profile_path: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Trailer {
|
||||||
|
iso_639_1: string;
|
||||||
|
iso_3166_1: string;
|
||||||
|
name: string;
|
||||||
|
key: string;
|
||||||
|
site: string;
|
||||||
|
size: number;
|
||||||
|
type: string;
|
||||||
|
official: boolean;
|
||||||
|
published_at: Date;
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface IDName<T = number> {
|
interface IDName<T = number> {
|
||||||
id: T;
|
id: T;
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
Reference in new issue
Block a user