feat: swiper

This commit is contained in:
ner committed 2024-03-23 11:20:30 +02:00
1 parent cd8928ab54
commit 12223b79d5
20 files changed
+222 -164

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ import ToggleSearch from './components/Search';
import ToggleTheme from './components/ThemeToggle';
const Header: FC = () => (
<header className='flex justify-center bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 sticky py-2 top-0 z-10'>
<header className='flex justify-center bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 sticky py-2 top-0 z-20'>
<div className='max-w-[1260px] w-full px-2'>
<div className='flex items-center justify-between gap-2 md:flex-nowrap'>
<Link href='/' shallow legacyBehavior>
+38 -16
View File
@@ -1,31 +1,48 @@
import { FC, ReactNode } from 'react';
import { FC } from 'react';
import { motion } from 'framer-motion';
import useFavorites, { useFavoritesMutation } from '@/app/(site)/favorites/useFavorites';
import Poster from '@/components/Movie/components/Poster';
import Rating from '@/components/Movie/components/Rating';
import Title from '@/components/Movie/components/Title';
import { cn } from '@/lib/utils';
interface Props {
movie?: Movie;
className?: string;
children?: ReactNode;
onClick?: () => void;
fit?: boolean;
}
const Card: FC<Props> = ({ movie, className, children, onClick }) => {
const Card: FC<Props> = ({ movie, onClick, fit }) => {
const { add, remove } = useFavoritesMutation();
const { map } = useFavorites();
if (!movie) return null;
const isFavorite = map.has(movie.id);
const handleToggleFavorite = () => (isFavorite ? remove(movie.id) : add(movie));
return (
<div
className={`${className} relative bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg`}
<motion.div
onDoubleClick={handleToggleFavorite}
onTap={onClick}
className={cn(
'w-[300px] h-[450px] shrink-0 mx-auto',
fit ? 'w-full h-auto xs:w-[300px] xs:h-[450px]' : undefined
)}
>
<motion.div className='flex justify-center grow' onTap={onClick}>
<Poster title={movie.title} width={300} height={450} size={100} poster={movie.poster_path} />
{children}
<div className='absolute left-0 top-0 w-full h-20 bg-gradient-to-t from-transparent to-black opacity-80'>
<div className='max-w-[300px] w-full mx-auto pt-1 px-3 text-white'>
<div className='flex flex-col w-full h-full mx-auto relative bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg'>
<Poster
title={movie.title}
size={100}
poster={movie.poster_path}
className={fit ? 'h-auto xs:h-full' : undefined}
/>
<div className='absolute left-0 top-0 w-full h-20 bg-gradient-to-t from-transparent to-black opacity-75'>
<div className='h-full w-full mx-auto pt-1 px-3 text-white'>
<div className='grid items-center grid-cols-[1fr_50px]'>
<Title title={movie.title} />
<Title key={movie.title} title={movie.title} />
{movie.release_date && (
<span className='flex justify-end text-lg font-semibold'>
{new Date(movie.release_date).getFullYear()}
@@ -34,11 +51,16 @@ const Card: FC<Props> = ({ movie, className, children, onClick }) => {
</div>
</div>
</div>
</motion.div>
<div className='absolute left-0 bottom-0 w-full bg-gradient-to-t from-black to-transparent h-20 text-white p-3 pb-2 flex flex-col justify-end opacity-80'>
<Rating movie={movie} iconsFillColor='fill-white' />
<div className='absolute left-0 bottom-0 w-full bg-gradient-to-t from-black to-transparent h-20 text-white p-3 pb-2 flex flex-col justify-end opacity-75'>
<Rating
isFavorite={isFavorite}
toggleFavorite={handleToggleFavorite}
rating={movie.vote_average}
iconsFillColor='fill-white'
/>
</div>
</div>
</div>
</motion.div>
);
};
+3 -2
View File
@@ -71,10 +71,10 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, withBottomGap = tr
<motion.li
key={movie.id}
variants={item}
className='flex basis-[300px] cursor-pointer'
className='flex cursor-pointer'
ref={isAnchor ? (element) => setLoader(element!) : undefined}
>
<Card movie={movie} className='grow flex flex-col' onClick={() => setMovie(movie)} />
<Card fit movie={movie} onClick={() => setMovie(movie)} />
</motion.li>
);
})}
@@ -85,6 +85,7 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, withBottomGap = tr
<Modal isOpen={Boolean(movie)} onClose={() => setMovie(null)} className='block p-0'>
{movie && (
<Preview
fit
key={movie.id}
movie={movie}
className='border-none'
@@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation';
import { Button } from '@/components/ui/button';
import { showTorrentsModal } from '../../components/Torrents';
import ToggleTrailer from '../../components/Trailer';
interface Props {
movie: Movie;
@@ -16,6 +17,13 @@ export default function Actions({ onClose, movie }: Props) {
return (
<>
<ToggleTrailer movieId={movie?.id}>
{({ onPlay, disabled }) => (
<Button className='h-8 flex-grow w-[50%]' onClick={onPlay} disabled={disabled}>
Trailer
</Button>
)}
</ToggleTrailer>
<Button
className='h-8 flex-grow w-[50%]'
onClick={() => showTorrentsModal({ title: movie.title, year: new Date(movie.release_date).getFullYear() })}
+7 -41
View File
@@ -1,10 +1,8 @@
'use client';
import { FC, ReactNode } from 'react';
import { AnimatePresence, motion } from 'framer-motion';
import Credits from '@/components/Movie/components/Credits';
import ToggleTrailer from '@/components/Movie/components/Trailer';
import { Separator } from '@/components/ui/separator';
import { cn } from '@/lib/utils';
@@ -13,62 +11,30 @@ import Card from '../Card';
import Actions from './components/Actions';
interface Props {
fit?: boolean;
movie?: Movie;
className?: string;
direction?: number;
onClose?: () => void;
children?: ReactNode;
renderCard?: () => ReactNode;
}
const variants = {
enter: (direction: number) => ({
scale: direction === 0 ? 1 : 0.8,
opacity: direction === 0 ? 1 : 0,
x: direction === 0 ? 0 : direction * 300
}),
center: { x: 0, opacity: 1, y: 0, scale: 1 },
exit: (direction: number) => ({ scale: 0.8, opacity: 1, x: direction * -300 })
};
const Preview: FC<Props> = ({ movie, className, direction, onClose, children }) => {
const Preview: FC<Props> = ({ movie, className, onClose, children, renderCard, fit }) => {
if (!movie) return null;
return (
<div className={cn('rounded-xl text-card-foreground', { 'p-2': Boolean(onClose) }, className)}>
<div className='flex flex-col lg:flex-row max-w-[100%] gap-2'>
<div className='max-w-[300px] min-w-[300px] h-[450px] mx-auto w-[100%] relative overflow-hidden rounded-lg'>
<AnimatePresence custom={direction}>
<motion.div
className='absolute'
initial='enter'
animate='center'
exit='exit'
key={movie?.id}
variants={variants}
custom={direction}
transition={{ type: 'tween' }}
>
<Card movie={movie} className='max-w-[300px] min-w-[300px] mx-auto w-full'>
<ToggleTrailer movieId={movie?.id} />
</Card>
</motion.div>
</AnimatePresence>
</div>
{renderCard?.() || <Card fit={fit} movie={movie} />}
<div className='flex flex-col grow'>
{children && <div className='flex w-full mb-2 gap-2'>{children}</div>}
{children && <div className='flex hover-none:hidden w-full mb-2 gap-2'>{children}</div>}
<div className='flex w-full gap-2'>
<Actions movie={movie} onClose={onClose} />
</div>
<Separator className='my-2' />
<motion.p
key={movie.id}
className='leading-7'
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
>
<p key={movie.id} className='leading-7'>
{movie.overview}
</motion.p>
</p>
</div>
</div>
<Credits movieId={movie.id} onPersonClick={onClose} />
@@ -36,7 +36,7 @@ const Credits: FC<Props> = ({ movieId, onPersonClick }) => {
return (
Boolean(credits?.length) && (
<div className='overflow-auto no-scrollbar max-w-[100%] py-2 pb-5 mb-[-0.75rem]'>
<div className='overflow-auto no-scrollbar max-w-[100%] py-2 mb-[-0.75rem]'>
<motion.ul className='flex gap-3' variants={container} initial='hidden' animate='visible' whileInView='visible'>
{credits?.map((actor) => (
<motion.li
+16 -25
View File
@@ -1,38 +1,29 @@
import { FC, ReactNode } from 'react';
import { FC } from 'react';
import { ImageOff } from 'lucide-react';
import Image from 'next/image';
import { cn } from '@/lib/utils';
interface Props {
title: string;
poster: string;
width: number;
height: number;
size: number;
className?: string;
children?: ReactNode;
}
const Poster: FC<Props> = ({ title, poster, width, height, size = 250, className, children }) => {
return (
<div
className={`w-full flex flex-col rounded-lg overflow-hidden shrink-0 lg:m-0 mx-auto relative ${className}`}
style={{ minHeight: poster ? '' : height }}
>
{poster ? (
<Image
className='rounded-lg mx-auto w-auto'
unoptimized
height={height}
width={width}
src={`https://image.tmdb.org/t/p/w500/${poster}`}
alt={title}
/>
) : (
<div className={`h-[${height}px] w-full flex items-center justify-center rounded-lg border grow`}>
<ImageOff size={size} strokeWidth={1} />
</div>
)}
{children}
const Poster: FC<Props> = ({ title, poster, size = 250, className }) => {
return poster ? (
<Image
className={cn('rounded-lg mx-auto w-auto h-full object-fill', className)}
unoptimized
height={750}
width={500}
src={`https://image.tmdb.org/t/p/w500/${poster}`}
alt={title}
/>
) : (
<div className={'w-full flex items-center justify-center rounded-lg grow'}>
<ImageOff size={size} strokeWidth={1} color='hsl(215.4 16.3% 46.9%)' />
</div>
);
};
+6 -11
View File
@@ -2,26 +2,21 @@ import { FC } from 'react';
import { motion } from 'framer-motion';
import { Heart, Star } from 'lucide-react';
import useFavorites, { useFavoritesMutation } from '@/app/(site)/favorites/useFavorites';
interface Props {
movie: Movie;
isFavorite: boolean;
toggleFavorite: () => void;
iconsFillColor?: string;
rating?: number;
}
const Rating: FC<Props> = ({ movie, iconsFillColor = 'fill-accent-foreground' }) => {
const { map } = useFavorites();
const { add, remove } = useFavoritesMutation();
const isFavorite = map.has(movie.id);
const Rating: FC<Props> = ({ isFavorite, rating, toggleFavorite, iconsFillColor = 'fill-accent-foreground' }) => {
return (
<span className='select-none flex w-full items-center ml-auto gap-1 mt-[-8px] justify-between'>
<motion.span
onTap={(event) => {
event.stopPropagation();
isFavorite ? remove(movie.id) : add(movie);
toggleFavorite();
}}
className='z-[2] cursor-pointer'
title={isFavorite ? 'Remove from favorites' : 'Add to favorite'}
@@ -30,7 +25,7 @@ const Rating: FC<Props> = ({ movie, iconsFillColor = 'fill-accent-foreground' })
</motion.span>
<span className='flex items-center'>
<Star size={18} className={`mr-1 ${iconsFillColor}`} />
<span className='font-semibold'>{movie.vote_average?.toFixed(1)}</span>
<span className='font-semibold'>{rating?.toFixed(1)}</span>
</span>
</span>
);
+15 -14
View File
@@ -1,6 +1,6 @@
'use client';
import { FC } from 'react';
import { FC, ReactNode } from 'react';
import { create, InstanceProps } from 'react-modal-promise';
import { motion } from 'framer-motion';
import { Play } from 'lucide-react';
@@ -10,6 +10,7 @@ import { Modal } from '@/components/ui/dialog';
interface Props {
movieId?: number;
children?: ({ onPlay, disabled }: { onPlay: () => void; disabled: boolean }) => ReactNode;
}
const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey, onResolve, isOpen }) => {
@@ -35,18 +36,18 @@ const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey
export const showTrailerModal = create(Trailer);
export default function ToggleTrailer({ movieId }: Props) {
const { data: trailer } = useTrailer({ movieId });
export default function ToggleTrailer({ movieId, children }: Props) {
const { data: trailer, isFetched } = useTrailer({ movieId });
return (
trailer && (
<motion.div
onTap={() => showTrailerModal({ trailerKey: trailer?.key })}
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' />
</motion.div>
)
);
return children
? children({ onPlay: () => showTrailerModal({ trailerKey: trailer?.key }), disabled: isFetched && !trailer })
: trailer && (
<motion.div
onTap={() => showTrailerModal({ trailerKey: trailer?.key })}
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' />
</motion.div>
);
}