feat: swiper
This commit is contained in:
1 parent
cd8928ab54
commit
12223b79d5
20 files changed
+222
-164
No files matched your search
+56
-27
@@ -1,11 +1,14 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { atomWithStorage } from 'jotai/utils';
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
import { ArrowLeft, ArrowRight, SlidersHorizontal } from 'lucide-react';
|
import { ArrowLeft, ArrowRight, SlidersHorizontal } from 'lucide-react';
|
||||||
|
import { EffectCreative } from 'swiper/modules';
|
||||||
|
import { Swiper, SwiperSlide } from 'swiper/react';
|
||||||
|
|
||||||
|
import Card from '@/components/Movie/Card';
|
||||||
import Movie from '@/components/Movie/Preview';
|
import Movie from '@/components/Movie/Preview';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import useMounted from '@/hooks/useMounted';
|
import useMounted from '@/hooks/useMounted';
|
||||||
@@ -17,10 +20,23 @@ import useRandomMovie from './useRandomMovie';
|
|||||||
|
|
||||||
const isShowFilterAtom = atomWithStorage('is-show-filters', false);
|
const isShowFilterAtom = atomWithStorage('is-show-filters', false);
|
||||||
|
|
||||||
|
const creativeEffectProps = {
|
||||||
|
creativeEffect: {
|
||||||
|
prev: {
|
||||||
|
shadow: true,
|
||||||
|
translate: ['-120%', 0, -500]
|
||||||
|
},
|
||||||
|
next: {
|
||||||
|
shadow: true,
|
||||||
|
translate: ['120%', 0, -500]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modules: [EffectCreative]
|
||||||
|
};
|
||||||
|
|
||||||
export default function Container() {
|
export default function Container() {
|
||||||
const [isShowFilter, setIsShowFilter] = useAtom(isShowFilterAtom);
|
const [isShowFilter, setIsShowFilter] = useAtom(isShowFilterAtom);
|
||||||
const { movie, next, previous, hasPrevious } = useRandomMovie();
|
const { ref, hasPrevious, movies, movie, next, previous, index, onIndexChange } = useRandomMovie();
|
||||||
const [direction, setDirection] = useState(0);
|
|
||||||
const isMounted = useMounted();
|
const isMounted = useMounted();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -29,37 +45,50 @@ export default function Container() {
|
|||||||
queryClient.prefetchQuery({ queryKey: ['genres'], queryFn: () => genres() });
|
queryClient.prefetchQuery({ queryKey: ['genres'], queryFn: () => genres() });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleChangeMovie = (direction: 1 | -1) => () => {
|
|
||||||
direction === 1 ? next() : previous();
|
|
||||||
setDirection(direction);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isShowFilter && <Filter />}
|
{isShowFilter && <Filter />}
|
||||||
<Movie movie={movie} direction={direction}>
|
{isMounted &&
|
||||||
<div className='gap-2 flex w-full bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 lg:static max-sm:z-10 max-sm:fixed max-sm:bottom-0 max-sm:left-0 max-sm:w-full max-sm:p-2 max-sm:px-2 max-sm:mb-0'>
|
createPortal(
|
||||||
<Button
|
<Button
|
||||||
className='grow h-12 sm:h-8'
|
className='p-2'
|
||||||
onClick={handleChangeMovie(-1)}
|
onClick={() => setIsShowFilter((isShow) => !isShow)}
|
||||||
disabled={!hasPrevious}
|
title={isShowFilter ? 'Hide filters' : 'Show filters'}
|
||||||
title='Previous movie'
|
variant='ghost'
|
||||||
>
|
>
|
||||||
|
<SlidersHorizontal size={19} />
|
||||||
|
</Button>,
|
||||||
|
document.getElementById('actions')!
|
||||||
|
)}
|
||||||
|
<Movie
|
||||||
|
movie={movie}
|
||||||
|
className='bg-background rounded-md'
|
||||||
|
renderCard={() => (
|
||||||
|
<Swiper
|
||||||
|
onSwiper={(instance) => (ref.current = instance)}
|
||||||
|
effect='creative'
|
||||||
|
lazyPreloadPrevNext={5}
|
||||||
|
resistance={false}
|
||||||
|
longSwipesRatio={0.25}
|
||||||
|
speed={600}
|
||||||
|
initialSlide={index}
|
||||||
|
onActiveIndexChange={onIndexChange}
|
||||||
|
className='w-[300px] shrink-0'
|
||||||
|
{...creativeEffectProps}
|
||||||
|
>
|
||||||
|
{movies?.map((movie) => (
|
||||||
|
<SwiperSlide key={movie.id}>
|
||||||
|
<Card movie={movie} />
|
||||||
|
</SwiperSlide>
|
||||||
|
))}
|
||||||
|
</Swiper>
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className='gap-2 flex w-full bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 lg:static max-sm:z-10 max-sm:fixed max-sm:bottom-0 max-sm:left-0 max-sm:w-full max-sm:p-2 max-sm:px-2 max-sm:mb-0'>
|
||||||
|
<Button className='grow h-8' onClick={previous} disabled={!hasPrevious} title='Previous movie'>
|
||||||
<ArrowLeft size={24} />
|
<ArrowLeft size={24} />
|
||||||
</Button>
|
</Button>
|
||||||
{isMounted &&
|
<Button className='grow h-8' onClick={next} title='Next movie'>
|
||||||
createPortal(
|
|
||||||
<Button
|
|
||||||
className='p-2'
|
|
||||||
onClick={() => setIsShowFilter((isShow) => !isShow)}
|
|
||||||
title={isShowFilter ? 'Hide filters' : 'Show filters'}
|
|
||||||
variant='ghost'
|
|
||||||
>
|
|
||||||
<SlidersHorizontal size={19} />
|
|
||||||
</Button>,
|
|
||||||
document.getElementById('actions')!
|
|
||||||
)}
|
|
||||||
<Button className='grow h-12 sm:h-8' onClick={handleChangeMovie(1)} title='Next movie'>
|
|
||||||
<ArrowRight size={24} />
|
<ArrowRight size={24} />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Container from './container';
|
import Container from './container';
|
||||||
|
|
||||||
export default async function Favorites() {
|
export default function Favorites() {
|
||||||
return <Container />;
|
return <Container />;
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ queryClient.prefetchInfiniteQuery({
|
|||||||
initialPageParam: '1'
|
initialPageParam: '1'
|
||||||
});
|
});
|
||||||
|
|
||||||
export default async function Popular() {
|
export default function Popular() {
|
||||||
return (
|
return (
|
||||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||||
<Container />
|
<Container />
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ queryClient.prefetchInfiniteQuery({
|
|||||||
initialPageParam: '1'
|
initialPageParam: '1'
|
||||||
});
|
});
|
||||||
|
|
||||||
export default async function Top() {
|
export default function Top() {
|
||||||
return (
|
return (
|
||||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||||
<Container />
|
<Container />
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import { Swiper } from 'swiper/types';
|
||||||
|
|
||||||
import useFilters from '@/app/(site)/useFilters';
|
import useFilters from '@/app/(site)/useFilters';
|
||||||
import { randomMovies } from '@/lib/api';
|
import { randomMovies } from '@/lib/api';
|
||||||
@@ -15,7 +16,8 @@ const useRandomMovie = () => {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { filters } = useFilters();
|
const { filters } = useFilters();
|
||||||
const indexByFilter = previousIndexes[JSON.stringify(filters)];
|
const indexByFilter = previousIndexes[JSON.stringify(filters)];
|
||||||
const [index, setIndex] = useState(indexByFilter || 0);
|
const [index, setIndex] = useState(indexByFilter);
|
||||||
|
const ref = useRef<Swiper>();
|
||||||
|
|
||||||
const { data: movies, refetch } = useQuery({
|
const { data: movies, refetch } = useQuery({
|
||||||
queryKey: ['random-movie', filters],
|
queryKey: ['random-movie', filters],
|
||||||
@@ -43,28 +45,25 @@ const useRandomMovie = () => {
|
|||||||
setIndex(indexByFilter || 0);
|
setIndex(indexByFilter || 0);
|
||||||
}, [indexByFilter]);
|
}, [indexByFilter]);
|
||||||
|
|
||||||
const previous = () => {
|
const previous = () => ref.current?.slidePrev();
|
||||||
if (!index) return;
|
|
||||||
|
|
||||||
setIndex((index) => index - 1);
|
const next = () => ref.current?.slideNext();
|
||||||
};
|
|
||||||
|
|
||||||
const next = () => {
|
|
||||||
if ((index && index % UPDATE_RATE === 0) || movies!.length < UPDATE_RATE) {
|
|
||||||
refetch();
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextIndex = index + 1;
|
|
||||||
|
|
||||||
previousIndexes[JSON.stringify(filters)] = nextIndex;
|
|
||||||
setIndex(nextIndex);
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
movies,
|
||||||
movie: movies?.[index],
|
movie: movies?.[index],
|
||||||
hasPrevious: index > 0,
|
hasPrevious: index > 0,
|
||||||
|
onIndexChange: ({ activeIndex }: Swiper) => {
|
||||||
|
if ((activeIndex && activeIndex % UPDATE_RATE === 0) || movies!.length < UPDATE_RATE) {
|
||||||
|
refetch();
|
||||||
|
}
|
||||||
|
previousIndexes[JSON.stringify(filters)] = activeIndex;
|
||||||
|
setIndex(activeIndex);
|
||||||
|
},
|
||||||
next,
|
next,
|
||||||
previous
|
previous,
|
||||||
|
index,
|
||||||
|
ref
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import React, { ReactNode } from 'react';
|
import React, { ReactNode } from 'react';
|
||||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
|
||||||
import type { Metadata, Viewport } from 'next';
|
import type { Metadata, Viewport } from 'next';
|
||||||
import { cookies } from 'next/headers';
|
import { cookies } from 'next/headers';
|
||||||
|
|
||||||
@@ -33,7 +32,6 @@ export default function RootLayout({ children }: { children: ReactNode }) {
|
|||||||
<Providers theme={theme}>
|
<Providers theme={theme}>
|
||||||
<Header />
|
<Header />
|
||||||
<main className='px-2 max-w-[1260px] mx-auto'>{children}</main>
|
<main className='px-2 max-w-[1260px] mx-auto'>{children}</main>
|
||||||
<ReactQueryDevtools initialIsOpen={false} />
|
|
||||||
</Providers>
|
</Providers>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import ToggleSearch from './components/Search';
|
|||||||
import ToggleTheme from './components/ThemeToggle';
|
import ToggleTheme from './components/ThemeToggle';
|
||||||
|
|
||||||
const Header: FC = () => (
|
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='max-w-[1260px] w-full px-2'>
|
||||||
<div className='flex items-center justify-between gap-2 md:flex-nowrap'>
|
<div className='flex items-center justify-between gap-2 md:flex-nowrap'>
|
||||||
<Link href='/' shallow legacyBehavior>
|
<Link href='/' shallow legacyBehavior>
|
||||||
|
|||||||
+38
-16
@@ -1,31 +1,48 @@
|
|||||||
import { FC, ReactNode } from 'react';
|
import { FC } from 'react';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
|
|
||||||
|
import useFavorites, { useFavoritesMutation } from '@/app/(site)/favorites/useFavorites';
|
||||||
import Poster from '@/components/Movie/components/Poster';
|
import Poster from '@/components/Movie/components/Poster';
|
||||||
import Rating from '@/components/Movie/components/Rating';
|
import Rating from '@/components/Movie/components/Rating';
|
||||||
import Title from '@/components/Movie/components/Title';
|
import Title from '@/components/Movie/components/Title';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
movie?: Movie;
|
movie?: Movie;
|
||||||
className?: string;
|
|
||||||
children?: ReactNode;
|
|
||||||
onClick?: () => void;
|
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;
|
if (!movie) return null;
|
||||||
|
|
||||||
|
const isFavorite = map.has(movie.id);
|
||||||
|
|
||||||
|
const handleToggleFavorite = () => (isFavorite ? remove(movie.id) : add(movie));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<motion.div
|
||||||
className={`${className} relative bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg`}
|
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}>
|
<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} width={300} height={450} size={100} poster={movie.poster_path} />
|
<Poster
|
||||||
{children}
|
title={movie.title}
|
||||||
<div className='absolute left-0 top-0 w-full h-20 bg-gradient-to-t from-transparent to-black opacity-80'>
|
size={100}
|
||||||
<div className='max-w-[300px] w-full mx-auto pt-1 px-3 text-white'>
|
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]'>
|
<div className='grid items-center grid-cols-[1fr_50px]'>
|
||||||
<Title title={movie.title} />
|
<Title key={movie.title} title={movie.title} />
|
||||||
{movie.release_date && (
|
{movie.release_date && (
|
||||||
<span className='flex justify-end text-lg font-semibold'>
|
<span className='flex justify-end text-lg font-semibold'>
|
||||||
{new Date(movie.release_date).getFullYear()}
|
{new Date(movie.release_date).getFullYear()}
|
||||||
@@ -34,11 +51,16 @@ const Card: FC<Props> = ({ movie, className, children, onClick }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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-75'>
|
||||||
<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
|
||||||
<Rating movie={movie} iconsFillColor='fill-white' />
|
isFavorite={isFavorite}
|
||||||
|
toggleFavorite={handleToggleFavorite}
|
||||||
|
rating={movie.vote_average}
|
||||||
|
iconsFillColor='fill-white'
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</motion.div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -71,10 +71,10 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, withBottomGap = tr
|
|||||||
<motion.li
|
<motion.li
|
||||||
key={movie.id}
|
key={movie.id}
|
||||||
variants={item}
|
variants={item}
|
||||||
className='flex basis-[300px] cursor-pointer'
|
className='flex cursor-pointer'
|
||||||
ref={isAnchor ? (element) => setLoader(element!) : undefined}
|
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>
|
</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'>
|
<Modal isOpen={Boolean(movie)} onClose={() => setMovie(null)} className='block p-0'>
|
||||||
{movie && (
|
{movie && (
|
||||||
<Preview
|
<Preview
|
||||||
|
fit
|
||||||
key={movie.id}
|
key={movie.id}
|
||||||
movie={movie}
|
movie={movie}
|
||||||
className='border-none'
|
className='border-none'
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
import { showTorrentsModal } from '../../components/Torrents';
|
import { showTorrentsModal } from '../../components/Torrents';
|
||||||
|
import ToggleTrailer from '../../components/Trailer';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
movie: Movie;
|
movie: Movie;
|
||||||
@@ -16,6 +17,13 @@ export default function Actions({ onClose, movie }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<ToggleTrailer movieId={movie?.id}>
|
||||||
|
{({ onPlay, disabled }) => (
|
||||||
|
<Button className='h-8 flex-grow w-[50%]' onClick={onPlay} disabled={disabled}>
|
||||||
|
Trailer
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</ToggleTrailer>
|
||||||
<Button
|
<Button
|
||||||
className='h-8 flex-grow w-[50%]'
|
className='h-8 flex-grow w-[50%]'
|
||||||
onClick={() => showTorrentsModal({ title: movie.title, year: new Date(movie.release_date).getFullYear() })}
|
onClick={() => showTorrentsModal({ title: movie.title, year: new Date(movie.release_date).getFullYear() })}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { FC, ReactNode } from 'react';
|
import { FC, ReactNode } from 'react';
|
||||||
import { AnimatePresence, motion } from 'framer-motion';
|
|
||||||
|
|
||||||
import Credits from '@/components/Movie/components/Credits';
|
import Credits from '@/components/Movie/components/Credits';
|
||||||
import ToggleTrailer from '@/components/Movie/components/Trailer';
|
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
@@ -13,62 +11,30 @@ import Card from '../Card';
|
|||||||
import Actions from './components/Actions';
|
import Actions from './components/Actions';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
fit?: boolean;
|
||||||
movie?: Movie;
|
movie?: Movie;
|
||||||
className?: string;
|
className?: string;
|
||||||
direction?: number;
|
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
|
renderCard?: () => ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const variants = {
|
const Preview: FC<Props> = ({ movie, className, onClose, children, renderCard, fit }) => {
|
||||||
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 }) => {
|
|
||||||
if (!movie) return null;
|
if (!movie) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('rounded-xl text-card-foreground', { 'p-2': Boolean(onClose) }, className)}>
|
<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='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'>
|
{renderCard?.() || <Card fit={fit} movie={movie} />}
|
||||||
<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>
|
|
||||||
<div className='flex flex-col grow'>
|
<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'>
|
<div className='flex w-full gap-2'>
|
||||||
<Actions movie={movie} onClose={onClose} />
|
<Actions movie={movie} onClose={onClose} />
|
||||||
</div>
|
</div>
|
||||||
<Separator className='my-2' />
|
<Separator className='my-2' />
|
||||||
<motion.p
|
<p key={movie.id} className='leading-7'>
|
||||||
key={movie.id}
|
|
||||||
className='leading-7'
|
|
||||||
initial={{ opacity: 0 }}
|
|
||||||
animate={{ opacity: 1 }}
|
|
||||||
exit={{ opacity: 0 }}
|
|
||||||
>
|
|
||||||
{movie.overview}
|
{movie.overview}
|
||||||
</motion.p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Credits movieId={movie.id} onPersonClick={onClose} />
|
<Credits movieId={movie.id} onPersonClick={onClose} />
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const Credits: FC<Props> = ({ movieId, onPersonClick }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
Boolean(credits?.length) && (
|
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'>
|
<motion.ul className='flex gap-3' variants={container} initial='hidden' animate='visible' whileInView='visible'>
|
||||||
{credits?.map((actor) => (
|
{credits?.map((actor) => (
|
||||||
<motion.li
|
<motion.li
|
||||||
|
|||||||
@@ -1,38 +1,29 @@
|
|||||||
import { FC, ReactNode } from 'react';
|
import { FC } from 'react';
|
||||||
import { ImageOff } from 'lucide-react';
|
import { ImageOff } from 'lucide-react';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
|
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title: string;
|
title: string;
|
||||||
poster: string;
|
poster: string;
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
size: number;
|
size: number;
|
||||||
className?: string;
|
className?: string;
|
||||||
children?: ReactNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Poster: FC<Props> = ({ title, poster, width, height, size = 250, className, children }) => {
|
const Poster: FC<Props> = ({ title, poster, size = 250, className }) => {
|
||||||
return (
|
return poster ? (
|
||||||
<div
|
<Image
|
||||||
className={`w-full flex flex-col rounded-lg overflow-hidden shrink-0 lg:m-0 mx-auto relative ${className}`}
|
className={cn('rounded-lg mx-auto w-auto h-full object-fill', className)}
|
||||||
style={{ minHeight: poster ? '' : height }}
|
unoptimized
|
||||||
>
|
height={750}
|
||||||
{poster ? (
|
width={500}
|
||||||
<Image
|
src={`https://image.tmdb.org/t/p/w500/${poster}`}
|
||||||
className='rounded-lg mx-auto w-auto'
|
alt={title}
|
||||||
unoptimized
|
/>
|
||||||
height={height}
|
) : (
|
||||||
width={width}
|
<div className={'w-full flex items-center justify-center rounded-lg grow'}>
|
||||||
src={`https://image.tmdb.org/t/p/w500/${poster}`}
|
<ImageOff size={size} strokeWidth={1} color='hsl(215.4 16.3% 46.9%)' />
|
||||||
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}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,26 +2,21 @@ import { FC } from 'react';
|
|||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { Heart, Star } from 'lucide-react';
|
import { Heart, Star } from 'lucide-react';
|
||||||
|
|
||||||
import useFavorites, { useFavoritesMutation } from '@/app/(site)/favorites/useFavorites';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
movie: Movie;
|
isFavorite: boolean;
|
||||||
|
toggleFavorite: () => void;
|
||||||
iconsFillColor?: string;
|
iconsFillColor?: string;
|
||||||
|
rating?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Rating: FC<Props> = ({ movie, iconsFillColor = 'fill-accent-foreground' }) => {
|
const Rating: FC<Props> = ({ isFavorite, rating, toggleFavorite, iconsFillColor = 'fill-accent-foreground' }) => {
|
||||||
const { map } = useFavorites();
|
|
||||||
const { add, remove } = useFavoritesMutation();
|
|
||||||
|
|
||||||
const isFavorite = map.has(movie.id);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className='select-none flex w-full items-center ml-auto gap-1 mt-[-8px] justify-between'>
|
<span className='select-none flex w-full items-center ml-auto gap-1 mt-[-8px] justify-between'>
|
||||||
<motion.span
|
<motion.span
|
||||||
onTap={(event) => {
|
onTap={(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
isFavorite ? remove(movie.id) : add(movie);
|
toggleFavorite();
|
||||||
}}
|
}}
|
||||||
className='z-[2] cursor-pointer'
|
className='z-[2] cursor-pointer'
|
||||||
title={isFavorite ? 'Remove from favorites' : 'Add to favorite'}
|
title={isFavorite ? 'Remove from favorites' : 'Add to favorite'}
|
||||||
@@ -30,7 +25,7 @@ const Rating: FC<Props> = ({ movie, iconsFillColor = 'fill-accent-foreground' })
|
|||||||
</motion.span>
|
</motion.span>
|
||||||
<span className='flex items-center'>
|
<span className='flex items-center'>
|
||||||
<Star size={18} className={`mr-1 ${iconsFillColor}`} />
|
<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>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { FC } from 'react';
|
import { FC, ReactNode } from 'react';
|
||||||
import { create, InstanceProps } from 'react-modal-promise';
|
import { create, InstanceProps } from 'react-modal-promise';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { Play } from 'lucide-react';
|
import { Play } from 'lucide-react';
|
||||||
@@ -10,6 +10,7 @@ import { Modal } from '@/components/ui/dialog';
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
movieId?: number;
|
movieId?: number;
|
||||||
|
children?: ({ onPlay, disabled }: { onPlay: () => void; disabled: boolean }) => ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey, onResolve, isOpen }) => {
|
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 const showTrailerModal = create(Trailer);
|
||||||
|
|
||||||
export default function ToggleTrailer({ movieId }: Props) {
|
export default function ToggleTrailer({ movieId, children }: Props) {
|
||||||
const { data: trailer } = useTrailer({ movieId });
|
const { data: trailer, isFetched } = useTrailer({ movieId });
|
||||||
|
|
||||||
return (
|
return children
|
||||||
trailer && (
|
? children({ onPlay: () => showTrailerModal({ trailerKey: trailer?.key }), disabled: isFetched && !trailer })
|
||||||
<motion.div
|
: trailer && (
|
||||||
onTap={() => showTrailerModal({ trailerKey: trailer?.key })}
|
<motion.div
|
||||||
title='Play trailer'
|
onTap={() => showTrailerModal({ trailerKey: trailer?.key })}
|
||||||
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'
|
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>
|
<Play size={100} className='fill-white' />
|
||||||
)
|
</motion.div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Generated
+38
-1
@@ -43,6 +43,7 @@
|
|||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-fast-marquee": "^1.6.0",
|
"react-fast-marquee": "^1.6.0",
|
||||||
"react-modal-promise": "^1.0.2",
|
"react-modal-promise": "^1.0.2",
|
||||||
|
"swiper": "^11.0.7",
|
||||||
"tailwind-merge": "^1.14.0",
|
"tailwind-merge": "^1.14.0",
|
||||||
"tailwindcss-animate": "^1.0.6",
|
"tailwindcss-animate": "^1.0.6",
|
||||||
"typescript": "5.1.6",
|
"typescript": "5.1.6",
|
||||||
@@ -58,7 +59,8 @@
|
|||||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||||
"postcss": "^8.4.27",
|
"postcss": "^8.4.27",
|
||||||
"prettier": "^3.0.0",
|
"prettier": "^3.0.0",
|
||||||
"tailwindcss": "^3.3.3"
|
"tailwindcss": "^3.3.3",
|
||||||
|
"tailwindcss-touch": "^1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@aashutoshrathi/word-wrap": {
|
"node_modules/@aashutoshrathi/word-wrap": {
|
||||||
@@ -6501,6 +6503,24 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/swiper": {
|
||||||
|
"version": "11.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/swiper/-/swiper-11.0.7.tgz",
|
||||||
|
"integrity": "sha512-cDfglW1B6uSmB6eB6pNmzDTNLmZtu5bWWa1vak0RU7fOI9qHjMzl7gVBvYSl34b0RU2N11HxxETJqQ5LeqI1cA==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/swiperjs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "open_collective",
|
||||||
|
"url": "http://opencollective.com/swiper"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 4.7.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/synckit": {
|
"node_modules/synckit": {
|
||||||
"version": "0.8.5",
|
"version": "0.8.5",
|
||||||
"resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.5.tgz",
|
"resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.5.tgz",
|
||||||
@@ -6569,6 +6589,12 @@
|
|||||||
"tailwindcss": ">=3.0.0 || insiders"
|
"tailwindcss": ">=3.0.0 || insiders"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/tailwindcss-touch": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tailwindcss-touch/-/tailwindcss-touch-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-h8A/S9+Mk2rnnaOB/NGCE7CxDhtGKbsAWf8Y2tCO6Zf381Y8dKcygPl1OXkFDnWXkL+FfHxmrGpwculDWAumbA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/tailwindcss/node_modules/postcss-js": {
|
"node_modules/tailwindcss/node_modules/postcss-js": {
|
||||||
"version": "4.0.1",
|
"version": "4.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/postcss-js/-/postcss-js-4.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/postcss-js/-/postcss-js-4.0.1.tgz",
|
||||||
@@ -11216,6 +11242,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",
|
||||||
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w=="
|
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w=="
|
||||||
},
|
},
|
||||||
|
"swiper": {
|
||||||
|
"version": "11.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/swiper/-/swiper-11.0.7.tgz",
|
||||||
|
"integrity": "sha512-cDfglW1B6uSmB6eB6pNmzDTNLmZtu5bWWa1vak0RU7fOI9qHjMzl7gVBvYSl34b0RU2N11HxxETJqQ5LeqI1cA=="
|
||||||
|
},
|
||||||
"synckit": {
|
"synckit": {
|
||||||
"version": "0.8.5",
|
"version": "0.8.5",
|
||||||
"resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.5.tgz",
|
"resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.5.tgz",
|
||||||
@@ -11275,6 +11306,12 @@
|
|||||||
"integrity": "sha512-4WigSGMvbl3gCCact62ZvOngA+PRqhAn7si3TQ3/ZuPuQZcIEtVap+ENSXbzWhpojKB8CpvnIsrwBu8/RnHtuw==",
|
"integrity": "sha512-4WigSGMvbl3gCCact62ZvOngA+PRqhAn7si3TQ3/ZuPuQZcIEtVap+ENSXbzWhpojKB8CpvnIsrwBu8/RnHtuw==",
|
||||||
"requires": {}
|
"requires": {}
|
||||||
},
|
},
|
||||||
|
"tailwindcss-touch": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tailwindcss-touch/-/tailwindcss-touch-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-h8A/S9+Mk2rnnaOB/NGCE7CxDhtGKbsAWf8Y2tCO6Zf381Y8dKcygPl1OXkFDnWXkL+FfHxmrGpwculDWAumbA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"tapable": {
|
"tapable": {
|
||||||
"version": "2.2.1",
|
"version": "2.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz",
|
||||||
|
|||||||
+3
-1
@@ -44,6 +44,7 @@
|
|||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-fast-marquee": "^1.6.0",
|
"react-fast-marquee": "^1.6.0",
|
||||||
"react-modal-promise": "^1.0.2",
|
"react-modal-promise": "^1.0.2",
|
||||||
|
"swiper": "^11.0.7",
|
||||||
"tailwind-merge": "^1.14.0",
|
"tailwind-merge": "^1.14.0",
|
||||||
"tailwindcss-animate": "^1.0.6",
|
"tailwindcss-animate": "^1.0.6",
|
||||||
"typescript": "5.1.6",
|
"typescript": "5.1.6",
|
||||||
@@ -59,6 +60,7 @@
|
|||||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||||
"postcss": "^8.4.27",
|
"postcss": "^8.4.27",
|
||||||
"prettier": "^3.0.0",
|
"prettier": "^3.0.0",
|
||||||
"tailwindcss": "^3.3.3"
|
"tailwindcss": "^3.3.3",
|
||||||
|
"tailwindcss-touch": "^1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
import { ReactNode, useState } from 'react';
|
import { ReactNode, useState } from 'react';
|
||||||
import ModalContainer from 'react-modal-promise';
|
import ModalContainer from 'react-modal-promise';
|
||||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||||
|
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
||||||
|
|
||||||
import { queryClientOptions } from '@/lib/queryClient';
|
import { queryClientOptions } from '@/lib/queryClient';
|
||||||
import ThemeProvider from '@/providers/Theme';
|
import ThemeProvider from '@/providers/Theme';
|
||||||
@@ -14,6 +15,7 @@ const Providers = ({ children, theme }: { children: ReactNode; theme?: Theme })
|
|||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
||||||
<ModalContainer />
|
<ModalContainer />
|
||||||
|
{/* <ReactQueryDevtools initialIsOpen={false} /> */}
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
|
@import url('~swiper/css');
|
||||||
|
@import url('~swiper/css/effect-creative');
|
||||||
|
@import url('~swiper/css/effect-coverflow');
|
||||||
|
|
||||||
@layer utilities {
|
@layer utilities {
|
||||||
.no-scrollbar::-webkit-scrollbar {
|
.no-scrollbar::-webkit-scrollbar {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
+4
-1
@@ -11,6 +11,9 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
extend: {
|
extend: {
|
||||||
|
screens: {
|
||||||
|
xs: '400px'
|
||||||
|
},
|
||||||
colors: {
|
colors: {
|
||||||
border: 'hsl(var(--border))',
|
border: 'hsl(var(--border))',
|
||||||
input: 'hsl(var(--input))',
|
input: 'hsl(var(--input))',
|
||||||
@@ -70,5 +73,5 @@ module.exports = {
|
|||||||
corePlugins: {
|
corePlugins: {
|
||||||
aspectRatio: false
|
aspectRatio: false
|
||||||
},
|
},
|
||||||
plugins: [require('tailwindcss-animate'), require('@tailwindcss/aspect-ratio')]
|
plugins: [require('tailwindcss-animate'), require('@tailwindcss/aspect-ratio'), require('tailwindcss-touch')()]
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user