diff --git a/app/(site)/container.tsx b/app/(site)/container.tsx index 18bb243..b6fc90f 100644 --- a/app/(site)/container.tsx +++ b/app/(site)/container.tsx @@ -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 && }
- -
diff --git a/components/Header/components/Navigation/index.tsx b/components/Header/components/Navigation/index.tsx new file mode 100644 index 0000000..5f000a6 --- /dev/null +++ b/components/Header/components/Navigation/index.tsx @@ -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 ( + + + {[ + ['/', 'Random'], + ['/top', 'Top'], + ['/favorites', 'Favorites'] + ].map(([path, label]) => ( + + + {label} + + + ))} + + + ); +} diff --git a/components/Header/components/Search/index.tsx b/components/Header/components/Search/index.tsx index cedf27e..4950058 100644 --- a/components/Header/components/Search/index.tsx +++ b/components/Header/components/Search/index.tsx @@ -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> = ({ isOpen, onResolve }) => { export const showSearchModal = create(Search); -export default Search; +export default function ToggleSearch() { + return ( + + ); +} diff --git a/components/Header/components/ThemeToggle/index.tsx b/components/Header/components/ThemeToggle/index.tsx new file mode 100644 index 0000000..c65be0d --- /dev/null +++ b/components/Header/components/ThemeToggle/index.tsx @@ -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 ( + + ); +} diff --git a/components/Header/index.tsx b/components/Header/index.tsx index 9b1c127..29969f8 100644 --- a/components/Header/index.tsx +++ b/components/Header/index.tsx @@ -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 ( -
-
- - Movie advisor - -
- - -
+const Header: FC = () => ( +
+
+ + Movie advisor + +
+ +
- - - {[ - ['/', 'Random'], - ['/top', 'Top'], - ['/favorites', 'Favorites'] - ].map(([path, label]) => ( - - - {label} - - - ))} - - -
- ); -}; +
+ +
+); export default Header; diff --git a/components/Movie/Card.tsx b/components/Movie/Card.tsx index faf0c93..2941c40 100644 --- a/components/Movie/Card.tsx +++ b/components/Movie/Card.tsx @@ -17,7 +17,7 @@ const Card: FC = ({ movie, className, children, onClick }) => { return (
diff --git a/components/Movie/Preview.tsx b/components/Movie/Preview.tsx deleted file mode 100644 index 63af000..0000000 --- a/components/Movie/Preview.tsx +++ /dev/null @@ -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 = ({ movie, className, onClose, direction }) => { - const { data: trailer } = useTrailer({ movieId: movie?.id }); - const router = useRouter(); - - if (!movie) return null; - - return ( -
-
-
- - - - {trailer && ( - 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' - > - - - )} - - - -
-
-
- - -
- - - {movie.overview} - -
-
- onClose?.()} /> -
- ); -}; - -export default Preview; diff --git a/components/Movie/Preview/components/Actions.tsx b/components/Movie/Preview/components/Actions.tsx new file mode 100644 index 0000000..a7de391 --- /dev/null +++ b/components/Movie/Preview/components/Actions.tsx @@ -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 ( + <> + + + + ); +} diff --git a/components/Movie/Preview/index.tsx b/components/Movie/Preview/index.tsx new file mode 100644 index 0000000..aeb62a4 --- /dev/null +++ b/components/Movie/Preview/index.tsx @@ -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 = ({ movie, className, direction, onClose }) => { + if (!movie) return null; + + return ( +
+
+
+ + + + + + + +
+
+
+ +
+ + + {movie.overview} + +
+
+ +
+ ); +}; + +export default Preview; diff --git a/components/Movie/components/Credits/index.tsx b/components/Movie/components/Credits/index.tsx index fe8de34..1b462f2 100644 --- a/components/Movie/components/Credits/index.tsx +++ b/components/Movie/components/Credits/index.tsx @@ -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 = ({ movieId, onPersonClick }) => { return ( Boolean(credits?.length) && (
- + {credits?.map((actor) => ( { - trailerKey?: string; +interface Props { + movieId?: number; } -const Trailer: FC = ({ trailerKey, onResolve, isOpen }) => { +const Trailer: FC<{ trailerKey?: string } & InstanceProps> = ({ trailerKey, onResolve, isOpen }) => { if (!trailerKey) return; return ( @@ -30,4 +35,18 @@ const Trailer: FC = ({ trailerKey, onResolve, isOpen }) => { export const showTrailerModal = create(Trailer); -export default Trailer; +export default function ToggleTrailer({ movieId }: Props) { + const { data: trailer } = useTrailer({ movieId }); + + return ( + trailer && ( + 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' + > + + + ) + ); +}