feat: Initialize project
This commit is contained in:
1 parent
eccc32337f
commit
3c1050898e
65 files changed
+5661
-596
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { FC } from 'react';
|
||||
import { Star } from 'lucide-react';
|
||||
|
||||
import Poster from '@/components/Movie/components/Poster';
|
||||
import Title from '@/components/Movie/components/Title';
|
||||
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const Card: FC<Props> = ({ movie, className }) => {
|
||||
if (!movie) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`${className} p-4 rounded-lg border bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg`}
|
||||
>
|
||||
<div>
|
||||
<div className='grid items-center grid-cols-[1fr_70px]'>
|
||||
<Title title={movie.title} />
|
||||
{movie.release_date && (
|
||||
<span className='flex justify-end text-lg font-semibold'>{new Date(movie.release_date).getFullYear()}</span>
|
||||
)}
|
||||
</div>
|
||||
<div className='flex w-full justify-between'>
|
||||
<Star />
|
||||
<span className='text-lg font-semibold'>{movie.vote_average}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex justify-center relative'>
|
||||
<Poster title={movie.title} width={300} height={450} size={100} poster={movie.poster_path} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Card;
|
||||
@@ -0,0 +1,67 @@
|
||||
import { FC, Fragment, useLayoutEffect, useState } from 'react';
|
||||
import { InfiniteData, useInfiniteQuery, UseInfiniteQueryResult } from '@tanstack/react-query';
|
||||
|
||||
import Card from '@/components/Movie/Card';
|
||||
import Preview from '@/components/Movie/Preview';
|
||||
import { Dialog, DialogContent } from '@/components/ui/dialog';
|
||||
|
||||
interface Props {
|
||||
pages: Array<MovieDBResponse>;
|
||||
hasNextPage: boolean;
|
||||
fetchNextPage: () => void;
|
||||
}
|
||||
|
||||
const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage }) => {
|
||||
const [movie, setMovie] = useState<Movie | null>(null);
|
||||
const [loader, setLoader] = useState<HTMLLIElement>();
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!loader || !hasNextPage) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
([{ isIntersecting }]) => {
|
||||
if (!isIntersecting) return;
|
||||
|
||||
fetchNextPage();
|
||||
},
|
||||
{
|
||||
threshold: 1
|
||||
}
|
||||
);
|
||||
|
||||
observer.observe(loader);
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, [fetchNextPage, loader, hasNextPage]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ul className='flex gap-3 flex-wrap'>
|
||||
{pages.map((page) => (
|
||||
<Fragment key={page.page}>
|
||||
{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' />
|
||||
</li>
|
||||
))}
|
||||
</Fragment>
|
||||
))}
|
||||
</ul>
|
||||
<div className='h-4 w-full'></div>
|
||||
{movie && (
|
||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setMovie(null)}>
|
||||
<DialogContent className='block p-0'>
|
||||
<Preview movie={movie} className='border-none' />
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default List;
|
||||
@@ -0,0 +1,75 @@
|
||||
import { FC } from 'react';
|
||||
import { Star, User2 } from 'lucide-react';
|
||||
import Image from 'next/image';
|
||||
|
||||
import useCredits from '@/app/(site)/useCredits';
|
||||
import Poster from '@/components/Movie/components/Poster';
|
||||
import Title from '@/components/Movie/components/Title';
|
||||
import { CardTitle } from '@/components/ui/card';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const Preview: FC<Props> = ({ movie, className }) => {
|
||||
const { data: credits } = useCredits({ movieId: movie?.id });
|
||||
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={250} poster={movie.poster_path} />
|
||||
<div className='flex flex-col grow lg:max-w-[calc(100%-(300px+0.75rem))]'>
|
||||
<div className='flex'>
|
||||
<div className='flex flex-row w-full items-end justify-between text-lg font-semibold'>
|
||||
<span>
|
||||
<Title title={movie.title} /> {movie.release_date && `(${new Date(movie.release_date).getFullYear()})`}
|
||||
</span>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Star />
|
||||
<span>{movie.vote_average}</span>
|
||||
</div>
|
||||
</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>
|
||||
);
|
||||
};
|
||||
|
||||
export default Preview;
|
||||
@@ -0,0 +1,34 @@
|
||||
import { FC } from 'react';
|
||||
import { ImageOff } from 'lucide-react';
|
||||
import Image from 'next/image';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
poster: string;
|
||||
width: number;
|
||||
height: number;
|
||||
size: number;
|
||||
}
|
||||
|
||||
const Poster: FC<Props> = ({ title, poster, width, height, size = 250 }) => {
|
||||
return (
|
||||
<div className='max-w-[300px] h-[450px] w-full rounded-lg overflow-hidden shrink-0 relative m-auto lg:m-0'>
|
||||
{poster ? (
|
||||
<Image
|
||||
className='rounded-lg '
|
||||
unoptimized
|
||||
height={height}
|
||||
width={width}
|
||||
src={`https://image.tmdb.org/t/p/w500/${poster}`}
|
||||
alt={title}
|
||||
/>
|
||||
) : (
|
||||
<div className={`w-[${width}px] h-[${height}px] flex items-center justify-center rounded-lg border`}>
|
||||
<ImageOff size={size} strokeWidth={1} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Poster;
|
||||
@@ -0,0 +1,35 @@
|
||||
import { FC, useState } from 'react';
|
||||
import Marquee from 'react-fast-marquee';
|
||||
|
||||
import { useTheme } from '@/hooks/useTheme';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
}
|
||||
|
||||
const Title: FC<Props> = ({ title }) => {
|
||||
const [isScrollableTitle, setIsScrollableTitle] = useState(false);
|
||||
const [theme] = useTheme();
|
||||
return (
|
||||
<Marquee
|
||||
play={isScrollableTitle}
|
||||
gradient={isScrollableTitle}
|
||||
gradientWidth={10}
|
||||
gradientColor={theme === 'light' ? [255, 255, 255] : [2, 8, 23]}
|
||||
className='movie-title overflow-hidden h-[30px] text-lg font-semibold'
|
||||
>
|
||||
<div
|
||||
ref={(element) => {
|
||||
const header = element?.closest('.movie-title') as HTMLDivElement;
|
||||
const isScrollableTitle = (header?.offsetWidth || 0) < (element?.offsetWidth || 0);
|
||||
|
||||
isScrollableTitle && setIsScrollableTitle(isScrollableTitle);
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</div>
|
||||
</Marquee>
|
||||
);
|
||||
};
|
||||
|
||||
export default Title;
|
||||
Reference in new issue
Block a user