diff --git a/app/(site)/container.tsx b/app/(site)/container.tsx index 8bd8975..18bb243 100644 --- a/app/(site)/container.tsx +++ b/app/(site)/container.tsx @@ -1,5 +1,6 @@ 'use client'; +import { useState } from 'react'; import { useAtom } from 'jotai'; import { atomWithStorage } from 'jotai/utils'; import { ArrowLeft, ArrowRight, SlidersHorizontal } from 'lucide-react'; @@ -15,12 +16,21 @@ const isShowFilterAtom = atomWithStorage('is-show-filters', false); export default function Container() { const [isShowFilter, setIsShowFilter] = useAtom(isShowFilterAtom); const { movie, next, previous, hasPrevious } = useRandomMovie(); + const [direction, setDirection] = useState(0); return ( <> {isShowFilter && }
- -
- +
); diff --git a/components/Header/components/Search/index.tsx b/components/Header/components/Search/index.tsx index b503493..cedf27e 100644 --- a/components/Header/components/Search/index.tsx +++ b/components/Header/components/Search/index.tsx @@ -1,15 +1,15 @@ -import { ChangeEvent, useRef, useState } from 'react'; -import { Search as SearchIcon, XCircle } from 'lucide-react'; +import { ChangeEvent, FC, useRef, useState } from 'react'; +import { create, InstanceProps } from 'react-modal-promise'; +import { XCircle } from 'lucide-react'; import List from '@/components/Movie/List'; import { Button } from '@/components/ui/button'; -import { Dialog, DialogContent } from '@/components/ui/dialog'; +import { Modal } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import useSearch from './useSearch'; -const Search = () => { - const [isShow, setIsShow] = useState(false); +const Search: FC> = ({ isOpen, onResolve }) => { const [title, setTitle] = useState(''); const [query, setQuery] = useState(''); const timeout = useRef(); @@ -31,54 +31,45 @@ const Search = () => { }; const handleClose = () => { - setIsShow(false); handleReset(); }; return ( - <> - - {isShow && ( - - setIsShow(false)}> -
- - -
- - {Boolean(results?.pages.length) && ( -
- -
- )} -
-
+ onResolve()}> +
+ + +
+ {Boolean(results?.pages.length) && ( +
+ +
)} - +
); }; +export const showSearchModal = create(Search); + export default Search; diff --git a/components/Header/index.tsx b/components/Header/index.tsx index 37c8ca2..9b1c127 100644 --- a/components/Header/index.tsx +++ b/components/Header/index.tsx @@ -1,7 +1,7 @@ 'use client'; import { FC } from 'react'; -import { Moon, Sun } from 'lucide-react'; +import { Moon, Search as SearchIcon, Sun } from 'lucide-react'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; @@ -10,7 +10,7 @@ import { Button } from '@/components/ui/button'; import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { useTheme } from '@/hooks/useTheme'; -import Search from './components/Search'; +import { showSearchModal } from './components/Search'; const Header: FC = () => { const path = usePathname(); @@ -26,7 +26,9 @@ const Header: FC = () => { - +
@@ -36,7 +38,7 @@ const Header: FC = () => { ['/top', 'Top'], ['/favorites', 'Favorites'] ].map(([path, label]) => ( - + {label} diff --git a/components/Movie/List.tsx b/components/Movie/List.tsx index f878fbe..03d131c 100644 --- a/components/Movie/List.tsx +++ b/components/Movie/List.tsx @@ -1,8 +1,9 @@ import { FC, Fragment, useLayoutEffect, useState } from 'react'; +import { motion } from 'framer-motion'; import Card from '@/components/Movie/Card'; import Preview from '@/components/Movie/Preview'; -import { Dialog, DialogContent } from '@/components/ui/dialog'; +import { Modal } from '@/components/ui/dialog'; import filterUnknownMovies from '@/lib/filterUnknownMovies'; interface Props { @@ -13,6 +14,23 @@ interface Props { onPreviewClose?: () => void; } +const container = { + hidden: {}, + visible: { + transition: { + staggerChildren: 0.15 + } + } +}; + +const item = { + hidden: { y: -20, opacity: 0 }, + visible: { + y: 0, + opacity: 1 + } +}; + const List: FC = ({ pages, hasNextPage, fetchNextPage, withBottomGap = true, onPreviewClose }) => { const [movie, setMovie] = useState(null); const [loader, setLoader] = useState(); @@ -38,39 +56,44 @@ const List: FC = ({ pages, hasNextPage, fetchNextPage, withBottomGap = tr return ( <> -
    + {pages.map((page) => ( {filterUnknownMovies(page.results)?.map((movie, index, array) => ( -
  • setMovie(movie)} + onTap={() => setMovie(movie)} ref={array.length / 2 !== index ? undefined : (element) => setLoader(element!)} > -
  • + ))}
    ))} -
+ {withBottomGap &&
} - {movie && ( - !isOpen && setMovie(null)}> - setMovie(null)}> - { - setMovie(null); - window.scrollTo({ top: 0, behavior: 'smooth' }); - onPreviewClose?.(); - }} - /> - - - )} + setMovie(null)} className='block p-0'> + {movie && ( + { + setMovie(null); + window.scrollTo({ top: 0, behavior: 'smooth' }); + onPreviewClose?.(); + }} + /> + )} + ); }; diff --git a/components/Movie/Preview.tsx b/components/Movie/Preview.tsx index 0b7cfe0..bc54fb9 100644 --- a/components/Movie/Preview.tsx +++ b/components/Movie/Preview.tsx @@ -1,70 +1,99 @@ -import { FC, useState } from 'react'; +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 Trailer from '@/components/Movie/components/Trailer'; +import { showTrailerModal } from '@/components/Movie/components/Trailer'; import { Separator } from '@/components/ui/separator'; import { Button } from '../ui/button'; -import Torrents from './components/Torrents'; +import { showTorrentsModal } from './components/Torrents'; import Card from './Card'; interface Props { movie?: Movie; className?: string; + direction?: number; onClose?: () => void; } -const Preview: FC = ({ movie, className, onClose }) => { - const [isShowTrailer, setIsShowTrailer] = useState(false); - const [isShowTorrents, setIsShowTorrents] = useState(false); +const variants = { + enter: (direction: number) => ({ + scale: 0.8, + opacity: 0, + [direction === 0 ? 'y' : 'x']: direction ? direction * -320 : -100 + }), + center: { x: 0, opacity: 1, y: 0, scale: 1 }, + exit: (direction: number) => ({ scale: 0.8, opacity: 1, [direction === 0 ? 'y' : 'x']: (direction || -1) * 320 }) +}; + +const Preview: FC = ({ movie, className, onClose, direction }) => { const { data: trailer } = useTrailer({ movieId: movie?.id }); const router = useRouter(); if (!movie) return null; return ( - <> -
-
- - {trailer && ( -
setIsShowTrailer(true)} - 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}

+
+
+
+ + + + {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?.()} />
- {isShowTrailer && setIsShowTrailer(false)} />} - {isShowTorrents && setIsShowTorrents(false)} />} - + onClose?.()} /> +
); }; diff --git a/components/Movie/components/Credits/index.tsx b/components/Movie/components/Credits/index.tsx index d90d327..fe8de34 100644 --- a/components/Movie/components/Credits/index.tsx +++ b/components/Movie/components/Credits/index.tsx @@ -1,4 +1,5 @@ import { FC } from 'react'; +import { motion } from 'framer-motion'; import { User2 } from 'lucide-react'; import Image from 'next/image'; import { useRouter } from 'next/navigation'; @@ -10,6 +11,23 @@ interface Props { onPersonClick?: (id: string) => void; } +const container = { + hidden: {}, + visible: { + transition: { + staggerChildren: 0.15 + } + } +}; + +const item = { + hidden: { x: -20, opacity: 0 }, + visible: { + x: 0, + opacity: 1 + } +}; + const Credits: FC = ({ movieId, onPersonClick }) => { const router = useRouter(); const { data: credits } = useCredits({ movieId }); @@ -17,12 +35,13 @@ const Credits: FC = ({ movieId, onPersonClick }) => { return ( Boolean(credits?.length) && (
-
    + {credits?.map((actor) => ( -
  • { + onTap={() => { router.push(`/top?starring=${actor.id}&title=${encodeURIComponent(actor.name)}`); onPersonClick?.(actor.id.toString()); }} @@ -47,9 +66,9 @@ const Credits: FC = ({ movieId, onPersonClick }) => { )}

{actor.name}

- + ))} - +
) ); diff --git a/components/Movie/components/Rating/index.tsx b/components/Movie/components/Rating/index.tsx index e0477a1..8991c00 100644 --- a/components/Movie/components/Rating/index.tsx +++ b/components/Movie/components/Rating/index.tsx @@ -1,4 +1,5 @@ import { FC } from 'react'; +import { motion } from 'framer-motion'; import { Heart, Star } from 'lucide-react'; import useFavorites, { useFavoritesMutation } from '@/app/(site)/favorites/useFavorites'; @@ -16,8 +17,8 @@ const Rating: FC = ({ movie, iconsFillColor = 'fill-accent-foreground' }) return ( - { + { event.stopPropagation(); isFavorite ? remove(movie.id) : add(movie); @@ -26,7 +27,7 @@ const Rating: FC = ({ movie, iconsFillColor = 'fill-accent-foreground' }) title={isFavorite ? 'Remove from favorites' : 'Add to favorite'} > - + {movie.vote_average?.toFixed(1)} diff --git a/components/Movie/components/Torrents/index.tsx b/components/Movie/components/Torrents/index.tsx index 16e50e7..0017765 100644 --- a/components/Movie/components/Torrents/index.tsx +++ b/components/Movie/components/Torrents/index.tsx @@ -1,18 +1,18 @@ import React, { Dispatch, FC, SetStateAction, useState } from 'react'; +import { create, InstanceProps } from 'react-modal-promise'; import { ArrowDownIcon, CaretSortIcon } from '@radix-ui/react-icons'; -import { useAtom } from 'jotai'; +import { useAtom, useAtomValue } from 'jotai'; import { atomWithStorage } from 'jotai/utils'; import { Cast, Loader, Magnet } from 'lucide-react'; import useTorrents from '@/app/(site)/useTorrents'; import { ORDER } from '@/app/api/torrents/parsers/pirate-bay'; -import { Dialog, DialogContent } from '@/components/ui/dialog'; +import { Modal } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; -interface Props { +interface Props extends InstanceProps { title: string; - onClose: () => void; } type Sorting = { @@ -49,9 +49,23 @@ const TableHeadSortable = ({ const hostAtom = atomWithStorage('magnet-host', ''); -const Torrents: FC = ({ title, onClose }) => { +const showHostManagerModal = create(({ onResolve, isOpen }) => { const [host, setHost] = useAtom(hostAtom); - const [isShowHostInput, setIsShowHostInput] = useState(false); + return ( + onResolve()}> + setHost(value)} + onKeyDown={({ key }) => key === 'Enter' && onResolve()} + /> + + ); +}); + +const Torrents: FC = ({ title, isOpen, onResolve }) => { + const host = useAtomValue(hostAtom); const [sorting, setSorting] = useState({ by: ORDER.seeders }); const { data: torrents, isLoading, isFetched } = useTorrents({ query: title, order: sorting.by }); @@ -64,81 +78,68 @@ const Torrents: FC = ({ title, onClose }) => { }; return ( - !isOpen && onClose()}> - - - - - Title - - - setIsShowHostInput(true)}> - Magnet - + onResolve()}> +
+ + + Title + + + showHostManagerModal()}> + Magnet + + + + + {torrents?.map((torrent) => ( + + {torrent.title} + +
{torrent.size}
+
+ {torrent.seeders} + +
+ {host ? ( + + + + ) : ( + + + + )} +
+
- - - {torrents?.map((torrent) => ( - - {torrent.title} - -
{torrent.size}
-
- {torrent.seeders} - -
- {host ? ( - - - - ) : ( - - - - )} -
-
-
- ))} - {isLoading && ( - - -
- -
-
-
- )} - {isFetched && !torrents?.length && ( - - -
- Nothing was found -
-
-
- )} -
-
- {isShowHostInput && ( - setIsShowHostInput(false)}> - setIsShowHostInput(false)}> - setHost(value)} - onKeyDown={({ key }) => key === 'Enter' && setIsShowHostInput(false)} - /> - - - )} -
-
+ ))} + {isLoading && ( + + +
+ +
+
+
+ )} + {isFetched && !torrents?.length && ( + + +
+ Nothing was found +
+
+
+ )} + + + ); }; +export const showTorrentsModal = create(Torrents); + export default Torrents; diff --git a/components/Movie/components/Trailer/index.tsx b/components/Movie/components/Trailer/index.tsx index 21d40f0..a869e9f 100644 --- a/components/Movie/components/Trailer/index.tsx +++ b/components/Movie/components/Trailer/index.tsx @@ -1,29 +1,33 @@ import { FC } from 'react'; +import { create, InstanceProps } from 'react-modal-promise'; -import { Dialog, DialogContent } from '@/components/ui/dialog'; +import { Modal } from '@/components/ui/dialog'; -interface Props { +interface Props extends InstanceProps { trailerKey?: string; - onClose: () => void; } -const Trailer: FC = ({ trailerKey, onClose }) => { +const Trailer: FC = ({ trailerKey, onResolve, isOpen }) => { + if (!trailerKey) return; + return ( - trailerKey && ( - !isOpen && onClose()}> - -