fix: animations
This commit is contained in:
1 parent
5f0dac673d
commit
83969a61a3
11 files changed
+202
-164
No files matched your search
@@ -18,19 +18,16 @@ export default function Container() {
|
||||
const { movie, next, previous, hasPrevious } = useRandomMovie();
|
||||
const [direction, setDirection] = useState(0);
|
||||
|
||||
const handleChangeMovie = (direction: 1 | -1) => () => {
|
||||
direction === 1 ? next() : previous();
|
||||
setDirection(direction);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{isShowFilter && <Filter />}
|
||||
<div className='gap-2 flex bg-background mb-2 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-[12px] max-sm:mb-0'>
|
||||
<Button
|
||||
className='p-2'
|
||||
onClick={() => {
|
||||
previous();
|
||||
setDirection(-1);
|
||||
}}
|
||||
disabled={!hasPrevious}
|
||||
title='Previous movie'
|
||||
>
|
||||
<Button className='p-2' onClick={handleChangeMovie(-1)} disabled={!hasPrevious} title='Previous movie'>
|
||||
<ArrowLeft size={24} strokeWidth={1} />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -41,15 +38,7 @@ export default function Container() {
|
||||
>
|
||||
<SlidersHorizontal size={24} strokeWidth={1} />
|
||||
</Button>
|
||||
<Button
|
||||
className='w-full p-2 grow'
|
||||
variant='default'
|
||||
onClick={() => {
|
||||
next();
|
||||
setDirection(1);
|
||||
}}
|
||||
title='Next movie'
|
||||
>
|
||||
<Button className='w-full p-2 grow' onClick={handleChangeMovie(1)} title='Next movie'>
|
||||
<ArrowRight size={24} strokeWidth={1} />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
|
||||
export default function Navigation() {
|
||||
const path = usePathname();
|
||||
return (
|
||||
<Tabs value={path} className='flex-grow mt-2'>
|
||||
<TabsList className='grid w-full grid-cols-3'>
|
||||
{[
|
||||
['/', 'Random'],
|
||||
['/top', 'Top'],
|
||||
['/favorites', 'Favorites']
|
||||
].map(([path, label]) => (
|
||||
<Link href={path} className='w-full' key={path}>
|
||||
<TabsTrigger className='w-full' value={path}>
|
||||
{label}
|
||||
</TabsTrigger>
|
||||
</Link>
|
||||
))}
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { ChangeEvent, FC, useRef, useState } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
import { XCircle } from 'lucide-react';
|
||||
import { Search as SearchIcon, XCircle } from 'lucide-react';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -72,4 +74,10 @@ const Search: FC<InstanceProps<void>> = ({ isOpen, onResolve }) => {
|
||||
|
||||
export const showSearchModal = create(Search);
|
||||
|
||||
export default Search;
|
||||
export default function ToggleSearch() {
|
||||
return (
|
||||
<Button variant='outline' size='icon' onClick={() => showSearchModal()}>
|
||||
<SearchIcon />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
'use client';
|
||||
|
||||
import { Moon, Sun } from 'lucide-react';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useTheme } from '@/hooks/useTheme';
|
||||
|
||||
export default function ThemeToggle() {
|
||||
const [theme, setTheme] = useTheme();
|
||||
return (
|
||||
<Button variant='outline' size='icon' onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
|
||||
{theme === 'light' ? <Moon /> : <Sun />}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -1,53 +1,25 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import { Moon, Search as SearchIcon, Sun } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { useTheme } from '@/hooks/useTheme';
|
||||
|
||||
import { showSearchModal } from './components/Search';
|
||||
import Navigation from './components/Navigation';
|
||||
import ToggleSearch from './components/Search';
|
||||
import ToggleTheme from './components/ThemeToggle';
|
||||
|
||||
const Header: FC = () => {
|
||||
const path = usePathname();
|
||||
const [theme, setTheme] = useTheme();
|
||||
|
||||
return (
|
||||
const Header: FC = () => (
|
||||
<header className='bg-background sticky pt-[12px] pb-2 top-0 z-10'>
|
||||
<div className='flex items-center justify-between'>
|
||||
<Link href='/'>
|
||||
<Badge className='whitespace-nowrap'>Movie advisor</Badge>
|
||||
</Link>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Button variant='outline' size='icon' onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
|
||||
{theme === 'light' ? <Moon /> : <Sun />}
|
||||
</Button>
|
||||
<Button variant='outline' size='icon' onClick={() => showSearchModal()}>
|
||||
<SearchIcon />
|
||||
</Button>
|
||||
<ToggleTheme />
|
||||
<ToggleSearch />
|
||||
</div>
|
||||
</div>
|
||||
<Tabs value={path} className='flex-grow mt-2'>
|
||||
<TabsList className='grid w-full grid-cols-3'>
|
||||
{[
|
||||
['/', 'Random'],
|
||||
['/top', 'Top'],
|
||||
['/favorites', 'Favorites']
|
||||
].map(([path, label]) => (
|
||||
<Link href={path} className='w-full' key={path}>
|
||||
<TabsTrigger className='w-full' value={path}>
|
||||
{label}
|
||||
</TabsTrigger>
|
||||
</Link>
|
||||
))}
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
<Navigation />
|
||||
</header>
|
||||
);
|
||||
};
|
||||
);
|
||||
|
||||
export default Header;
|
||||
@@ -17,7 +17,7 @@ const Card: FC<Props> = ({ movie, className, children, onClick }) => {
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`${className} rounded-lg relative bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg`}
|
||||
className={`${className} relative bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg`}
|
||||
>
|
||||
<motion.div className='flex justify-center grow' onTap={onClick}>
|
||||
<Poster title={movie.title} width={300} height={450} size={100} poster={movie.poster_path} />
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
import { FC } from 'react';
|
||||
import { AnimatePresence, motion } from 'framer-motion';
|
||||
import { Play } from 'lucide-react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import useTrailer from '@/app/(site)/useTrailer';
|
||||
import Credits from '@/components/Movie/components/Credits';
|
||||
import { showTrailerModal } from '@/components/Movie/components/Trailer';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
|
||||
import { Button } from '../ui/button';
|
||||
|
||||
import { showTorrentsModal } from './components/Torrents';
|
||||
import Card from './Card';
|
||||
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
className?: string;
|
||||
direction?: number;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
const variants = {
|
||||
enter: (direction: number) => ({
|
||||
scale: 0.8,
|
||||
opacity: 0,
|
||||
[direction === 0 ? 'y' : 'x']: direction === 0 ? -100 : direction * -320
|
||||
}),
|
||||
center: { x: 0, opacity: 1, y: 0, scale: 1 },
|
||||
exit: (direction: number) => ({ scale: 0.8, opacity: 1, x: direction * 320 })
|
||||
};
|
||||
|
||||
const Preview: FC<Props> = ({ movie, className, onClose, direction }) => {
|
||||
const { data: trailer } = useTrailer({ movieId: movie?.id });
|
||||
const router = useRouter();
|
||||
|
||||
if (!movie) return null;
|
||||
|
||||
return (
|
||||
<div className={`rounded-xl bg-card text-card-foreground ${className} ${onClose ? 'p-2' : ''}`}>
|
||||
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3'>
|
||||
<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'>
|
||||
{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>
|
||||
)}
|
||||
</Card>
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
<div className='flex flex-col grow'>
|
||||
<div className='flex w-full gap-2'>
|
||||
<Button className='h-8 grow' onClick={() => showTorrentsModal({ title: movie.title })}>
|
||||
Torrents
|
||||
</Button>
|
||||
<Button
|
||||
className='h-8 grow'
|
||||
onClick={() => {
|
||||
router.push(`/top?similar=${movie.id}&title=${encodeURIComponent(movie.title)}`);
|
||||
onClose?.();
|
||||
}}
|
||||
>
|
||||
Similar
|
||||
</Button>
|
||||
</div>
|
||||
<Separator className='my-2' />
|
||||
<motion.p
|
||||
key={movie.id}
|
||||
className='leading-7'
|
||||
initial={{ opacity: 0, y: -100 }}
|
||||
animate={{ y: 0, opacity: 1 }}
|
||||
exit={{ y: 100, opacity: 0 }}
|
||||
>
|
||||
{movie.overview}
|
||||
</motion.p>
|
||||
</div>
|
||||
</div>
|
||||
<Credits movieId={movie.id} onPersonClick={() => onClose?.()} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Preview;
|
||||
@@ -0,0 +1,33 @@
|
||||
'use client';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
import { showTorrentsModal } from '../../components/Torrents';
|
||||
|
||||
interface Props {
|
||||
movie: Movie;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
export default function Actions({ onClose, movie }: Props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button className='h-8 grow' onClick={() => showTorrentsModal({ title: movie.title })}>
|
||||
Torrents
|
||||
</Button>
|
||||
<Button
|
||||
className='h-8 grow'
|
||||
onClick={() => {
|
||||
router.push(`/top?similar=${movie.id}&title=${encodeURIComponent(movie.title)}`);
|
||||
onClose?.();
|
||||
}}
|
||||
>
|
||||
Similar
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { FC } 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';
|
||||
|
||||
import Card from '../Card';
|
||||
|
||||
import Actions from './components/Actions';
|
||||
|
||||
interface Props {
|
||||
movie?: Movie;
|
||||
className?: string;
|
||||
direction?: number;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
const variants = {
|
||||
enter: (direction: number) => ({
|
||||
scale: 0.8,
|
||||
opacity: 0,
|
||||
[direction === 0 ? 'y' : 'x']: direction === 0 ? -100 : 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 }) => {
|
||||
if (!movie) return null;
|
||||
|
||||
return (
|
||||
<div className={cn('rounded-xl bg-card text-card-foreground', { 'p-2': Boolean(onClose) }, className)}>
|
||||
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3'>
|
||||
<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>
|
||||
<div className='flex flex-col grow'>
|
||||
<div className='flex w-full gap-2'>
|
||||
<Actions movie={movie} />
|
||||
</div>
|
||||
<Separator className='my-2' />
|
||||
<motion.p
|
||||
key={movie.id}
|
||||
className='leading-7'
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
>
|
||||
{movie.overview}
|
||||
</motion.p>
|
||||
</div>
|
||||
</div>
|
||||
<Credits movieId={movie.id} onPersonClick={onClose} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Preview;
|
||||
@@ -1,5 +1,5 @@
|
||||
import { FC } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
import { FC, useEffect, useRef } from 'react';
|
||||
import { motion, useAnimation, useInView } from 'framer-motion';
|
||||
import { User2 } from 'lucide-react';
|
||||
import Image from 'next/image';
|
||||
import { useRouter } from 'next/navigation';
|
||||
@@ -35,7 +35,7 @@ const Credits: FC<Props> = ({ movieId, onPersonClick }) => {
|
||||
return (
|
||||
Boolean(credits?.length) && (
|
||||
<div className='overflow-auto max-w-[100%] py-3 mb-[-0.75rem]'>
|
||||
<motion.ul className='flex gap-3' variants={container} initial='hidden' animate='visible' layout>
|
||||
<motion.ul className='flex gap-3' variants={container} initial='hidden' animate='visible' whileInView='visible'>
|
||||
{credits?.map((actor) => (
|
||||
<motion.li
|
||||
variants={item}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
import { motion } from 'framer-motion';
|
||||
import { Play } from 'lucide-react';
|
||||
|
||||
import useTrailer from '@/app/(site)/useTrailer';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
|
||||
interface Props extends InstanceProps<void> {
|
||||
trailerKey?: string;
|
||||
interface Props {
|
||||
movieId?: number;
|
||||
}
|
||||
|
||||
const Trailer: FC<Props> = ({ trailerKey, onResolve, isOpen }) => {
|
||||
const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey, onResolve, isOpen }) => {
|
||||
if (!trailerKey) return;
|
||||
|
||||
return (
|
||||
@@ -30,4 +35,18 @@ const Trailer: FC<Props> = ({ trailerKey, onResolve, isOpen }) => {
|
||||
|
||||
export const showTrailerModal = create(Trailer);
|
||||
|
||||
export default Trailer;
|
||||
export default function ToggleTrailer({ movieId }: Props) {
|
||||
const { data: trailer } = 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>
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user