feat: animations
This commit is contained in:
1 parent
e4788ae384
commit
7b55619cf5
16 files changed
+643
-320
No files matched your search
@@ -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<InstanceProps<void>> = ({ isOpen, onResolve }) => {
|
||||
const [title, setTitle] = useState('');
|
||||
const [query, setQuery] = useState('');
|
||||
const timeout = useRef<NodeJS.Timeout>();
|
||||
@@ -31,54 +31,45 @@ const Search = () => {
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setIsShow(false);
|
||||
handleReset();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button variant='outline' size='icon' onClick={() => setIsShow(true)}>
|
||||
<SearchIcon />
|
||||
</Button>
|
||||
{isShow && (
|
||||
<Dialog defaultOpen={true} onOpenChange={handleClose}>
|
||||
<DialogContent className='block p-3 max-w-[950px]' onClose={() => setIsShow(false)}>
|
||||
<div className='relative'>
|
||||
<Input
|
||||
ref={inputRef}
|
||||
autoFocus
|
||||
placeholder='Start entering title...'
|
||||
value={title}
|
||||
onChange={handleChangeTitle}
|
||||
className='pr-10'
|
||||
/>
|
||||
<Button
|
||||
variant='outline'
|
||||
size='icon'
|
||||
onClick={handleReset}
|
||||
disabled={!query.length}
|
||||
className='absolute right-0 top-0'
|
||||
>
|
||||
<XCircle />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{Boolean(results?.pages.length) && (
|
||||
<div className='mt-3'>
|
||||
<List
|
||||
pages={results!.pages}
|
||||
fetchNextPage={fetchNextPage}
|
||||
hasNextPage={hasNextPage}
|
||||
withBottomGap={false}
|
||||
onPreviewClose={handleClose}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<Modal className='block p-3 max-w-[950px]' isOpen={isOpen} onClose={() => onResolve()}>
|
||||
<div className='relative'>
|
||||
<Input
|
||||
ref={inputRef}
|
||||
autoFocus
|
||||
placeholder='Start entering title...'
|
||||
value={title}
|
||||
onChange={handleChangeTitle}
|
||||
className='pr-10'
|
||||
/>
|
||||
<Button
|
||||
variant='outline'
|
||||
size='icon'
|
||||
onClick={handleReset}
|
||||
disabled={!query.length}
|
||||
className='absolute right-0 top-0'
|
||||
>
|
||||
<XCircle />
|
||||
</Button>
|
||||
</div>
|
||||
{Boolean(results?.pages.length) && (
|
||||
<div className='mt-3'>
|
||||
<List
|
||||
pages={results!.pages}
|
||||
fetchNextPage={fetchNextPage}
|
||||
hasNextPage={hasNextPage}
|
||||
withBottomGap={false}
|
||||
onPreviewClose={handleClose}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export const showSearchModal = create(Search);
|
||||
|
||||
export default Search;
|
||||
@@ -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 = () => {
|
||||
<Button variant='outline' size='icon' onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
|
||||
{theme === 'light' ? <Moon /> : <Sun />}
|
||||
</Button>
|
||||
<Search />
|
||||
<Button variant='outline' size='icon' onClick={() => showSearchModal()}>
|
||||
<SearchIcon />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Tabs value={path} className='flex-grow mt-2'>
|
||||
@@ -36,7 +38,7 @@ const Header: FC = () => {
|
||||
['/top', 'Top'],
|
||||
['/favorites', 'Favorites']
|
||||
].map(([path, label]) => (
|
||||
<Link href={path} className='w-full' key={path} prefetch>
|
||||
<Link href={path} className='w-full' key={path}>
|
||||
<TabsTrigger className='w-full' value={path}>
|
||||
{label}
|
||||
</TabsTrigger>
|
||||
|
||||
+45
-22
@@ -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<Props> = ({ pages, hasNextPage, fetchNextPage, withBottomGap = true, onPreviewClose }) => {
|
||||
const [movie, setMovie] = useState<Movie | null>(null);
|
||||
const [loader, setLoader] = useState<HTMLLIElement>();
|
||||
@@ -38,39 +56,44 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, withBottomGap = tr
|
||||
|
||||
return (
|
||||
<>
|
||||
<ul className='flex gap-3 flex-wrap justify-center grow'>
|
||||
<motion.ul
|
||||
className='flex gap-3 flex-wrap justify-center grow'
|
||||
variants={container}
|
||||
initial='hidden'
|
||||
animate='visible'
|
||||
layout
|
||||
>
|
||||
{pages.map((page) => (
|
||||
<Fragment key={page.page}>
|
||||
{filterUnknownMovies(page.results)?.map((movie, index, array) => (
|
||||
<li
|
||||
<motion.li
|
||||
key={movie.id}
|
||||
variants={item}
|
||||
className='flex basis-[300px] cursor-pointer'
|
||||
onClick={() => setMovie(movie)}
|
||||
onTap={() => setMovie(movie)}
|
||||
ref={array.length / 2 !== index ? undefined : (element) => setLoader(element!)}
|
||||
>
|
||||
<Card movie={movie} className='grow flex flex-col' />
|
||||
</li>
|
||||
</motion.li>
|
||||
))}
|
||||
</Fragment>
|
||||
))}
|
||||
</ul>
|
||||
</motion.ul>
|
||||
{withBottomGap && <div className='h-4 w-full' />}
|
||||
{movie && (
|
||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setMovie(null)}>
|
||||
<DialogContent className='block p-0' onClose={() => setMovie(null)}>
|
||||
<Preview
|
||||
key={movie.id}
|
||||
movie={movie}
|
||||
className='border-none'
|
||||
onClose={() => {
|
||||
setMovie(null);
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
onPreviewClose?.();
|
||||
}}
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
<Modal isOpen={Boolean(movie)} onClose={() => setMovie(null)} className='block p-0'>
|
||||
{movie && (
|
||||
<Preview
|
||||
key={movie.id}
|
||||
movie={movie}
|
||||
className='border-none'
|
||||
onClose={() => {
|
||||
setMovie(null);
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
onPreviewClose?.();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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<Props> = ({ 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<Props> = ({ movie, className, onClose, direction }) => {
|
||||
const { data: trailer } = useTrailer({ movieId: movie?.id });
|
||||
const router = useRouter();
|
||||
|
||||
if (!movie) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={`p-3 rounded-xl border bg-card text-card-foreground shadow-sm ${className}`}>
|
||||
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3'>
|
||||
<Card movie={movie} className='max-w-[300px] min-w-[300px] mx-auto w-full'>
|
||||
{trailer && (
|
||||
<div
|
||||
onClick={() => 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'
|
||||
>
|
||||
<Play size={100} className='fill-white' />
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
<div className='flex flex-col grow'>
|
||||
<div className='flex w-full gap-2'>
|
||||
<Button className='h-8 grow' onClick={() => setIsShowTorrents(true)}>
|
||||
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' />
|
||||
<p className='leading-7'>{movie.overview}</p>
|
||||
<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>
|
||||
<Credits movieId={movie.id} onPersonClick={() => onClose?.()} />
|
||||
</div>
|
||||
{isShowTrailer && <Trailer trailerKey={trailer?.key} onClose={() => setIsShowTrailer(false)} />}
|
||||
{isShowTorrents && <Torrents title={movie.title} onClose={() => setIsShowTorrents(false)} />}
|
||||
</>
|
||||
<Credits movieId={movie.id} onPersonClick={() => onClose?.()} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -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<Props> = ({ movieId, onPersonClick }) => {
|
||||
const router = useRouter();
|
||||
const { data: credits } = useCredits({ movieId });
|
||||
@@ -17,12 +35,13 @@ const Credits: FC<Props> = ({ movieId, onPersonClick }) => {
|
||||
return (
|
||||
Boolean(credits?.length) && (
|
||||
<div className='overflow-auto max-w-[100%] py-3 mb-[-0.75rem]'>
|
||||
<ul className='flex gap-3'>
|
||||
<motion.ul className='flex gap-3' variants={container} initial='hidden' animate='visible' layout>
|
||||
{credits?.map((actor) => (
|
||||
<li
|
||||
<motion.li
|
||||
variants={item}
|
||||
key={`${actor.id}_${actor.cast_id}`}
|
||||
title={actor.name}
|
||||
onClick={() => {
|
||||
onTap={() => {
|
||||
router.push(`/top?starring=${actor.id}&title=${encodeURIComponent(actor.name)}`);
|
||||
onPersonClick?.(actor.id.toString());
|
||||
}}
|
||||
@@ -47,9 +66,9 @@ const Credits: FC<Props> = ({ movieId, onPersonClick }) => {
|
||||
)}
|
||||
</div>
|
||||
<p className='pt-2 overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.name}</p>
|
||||
</li>
|
||||
</motion.li>
|
||||
))}
|
||||
</ul>
|
||||
</motion.ul>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
|
||||
@@ -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<Props> = ({ movie, iconsFillColor = 'fill-accent-foreground' })
|
||||
|
||||
return (
|
||||
<span className='select-none flex w-full items-center ml-auto gap-1 mt-[-8px] justify-between'>
|
||||
<span
|
||||
onClick={(event) => {
|
||||
<motion.span
|
||||
onTap={(event) => {
|
||||
event.stopPropagation();
|
||||
|
||||
isFavorite ? remove(movie.id) : add(movie);
|
||||
@@ -26,7 +27,7 @@ const Rating: FC<Props> = ({ movie, iconsFillColor = 'fill-accent-foreground' })
|
||||
title={isFavorite ? 'Remove from favorites' : 'Add to favorite'}
|
||||
>
|
||||
<Heart className={isFavorite ? iconsFillColor : ''} size={20} />
|
||||
</span>
|
||||
</motion.span>
|
||||
<span className='flex items-center'>
|
||||
<Star size={18} className={`mr-1 ${iconsFillColor}`} />
|
||||
<span className='font-semibold'>{movie.vote_average?.toFixed(1)}</span>
|
||||
|
||||
@@ -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<void> {
|
||||
title: string;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
type Sorting = {
|
||||
@@ -49,9 +49,23 @@ const TableHeadSortable = ({
|
||||
|
||||
const hostAtom = atomWithStorage<string>('magnet-host', '');
|
||||
|
||||
const Torrents: FC<Props> = ({ title, onClose }) => {
|
||||
const showHostManagerModal = create(({ onResolve, isOpen }) => {
|
||||
const [host, setHost] = useAtom(hostAtom);
|
||||
const [isShowHostInput, setIsShowHostInput] = useState(false);
|
||||
return (
|
||||
<Modal className='p-3 pt-0 max-w-[200px] m-auto' isOpen={isOpen} onClose={() => onResolve()}>
|
||||
<Input
|
||||
autoFocus
|
||||
placeholder='Enter host of Elementum'
|
||||
value={host}
|
||||
onChange={({ target: { value } }) => setHost(value)}
|
||||
onKeyDown={({ key }) => key === 'Enter' && onResolve()}
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
const Torrents: FC<Props> = ({ title, isOpen, onResolve }) => {
|
||||
const host = useAtomValue(hostAtom);
|
||||
const [sorting, setSorting] = useState<Sorting>({ by: ORDER.seeders });
|
||||
|
||||
const { data: torrents, isLoading, isFetched } = useTorrents({ query: title, order: sorting.by });
|
||||
@@ -64,81 +78,68 @@ const Torrents: FC<Props> = ({ title, onClose }) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && onClose()}>
|
||||
<DialogContent className='p-0' onClose={onClose}>
|
||||
<Table className='rounded-xl overflow-hidden'>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className='px-2'>Title</TableHead>
|
||||
<TableHeadSortable title='Size' by={ORDER.size} value={sorting} onChange={setSorting} />
|
||||
<TableHeadSortable title='Seeders' by={ORDER.seeders} value={sorting} onChange={setSorting} />
|
||||
<TableHead className='px-2 text-center' onClick={() => setIsShowHostInput(true)}>
|
||||
Magnet
|
||||
</TableHead>
|
||||
<Modal className='p-0' isOpen={isOpen} onClose={() => onResolve()}>
|
||||
<Table className='rounded-xl overflow-hidden'>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className='px-2'>Title</TableHead>
|
||||
<TableHeadSortable title='Size' by={ORDER.size} value={sorting} onChange={setSorting} />
|
||||
<TableHeadSortable title='Seeders' by={ORDER.seeders} value={sorting} onChange={setSorting} />
|
||||
<TableHead className='px-2 text-center cursor-pointer select-none' onClick={() => showHostManagerModal()}>
|
||||
Magnet
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{torrents?.map((torrent) => (
|
||||
<TableRow key={torrent.magnet + torrent.id}>
|
||||
<TableCell className='break-all p-2'>{torrent.title}</TableCell>
|
||||
<TableCell className='p-2'>
|
||||
<div className='flex items-center gap-1 shrink-0 justify-center'>{torrent.size}</div>
|
||||
</TableCell>
|
||||
<TableCell className='text-center p-2'>{torrent.seeders}</TableCell>
|
||||
<TableCell className='text-center p-1'>
|
||||
<div className='flex gap-2 m-auto justify-center'>
|
||||
{host ? (
|
||||
<a
|
||||
onClick={handleCast(torrent.magnet)}
|
||||
className='flex items-center justify-center h-8 w-8 border rounded-lg'
|
||||
>
|
||||
<Cast size={20} />
|
||||
</a>
|
||||
) : (
|
||||
<a href={torrent.magnet} className='flex items-center justify-center h-8 w-8 border rounded-lg'>
|
||||
<Magnet size={20} />
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{torrents?.map((torrent) => (
|
||||
<TableRow key={torrent.magnet + torrent.id}>
|
||||
<TableCell className='break-all p-2'>{torrent.title}</TableCell>
|
||||
<TableCell className='p-2'>
|
||||
<div className='flex items-center gap-1 shrink-0 justify-center'>{torrent.size}</div>
|
||||
</TableCell>
|
||||
<TableCell className='text-center p-2'>{torrent.seeders}</TableCell>
|
||||
<TableCell className='text-center p-1'>
|
||||
<div className='flex gap-2 m-auto justify-center'>
|
||||
{host ? (
|
||||
<a
|
||||
onClick={handleCast(torrent.magnet)}
|
||||
className='flex items-center justify-center h-8 w-8 border rounded-lg'
|
||||
>
|
||||
<Cast size={20} />
|
||||
</a>
|
||||
) : (
|
||||
<a href={torrent.magnet} className='flex items-center justify-center h-8 w-8 border rounded-lg'>
|
||||
<Magnet size={20} />
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{isLoading && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={4}>
|
||||
<div className='h-40 w-full flex items-center justify-center'>
|
||||
<Loader className='animate-spin' />
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{isFetched && !torrents?.length && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={4}>
|
||||
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
|
||||
Nothing was found
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
{isShowHostInput && (
|
||||
<Dialog defaultOpen={true} onOpenChange={() => setIsShowHostInput(false)}>
|
||||
<DialogContent className='flex p-3 max-w-[300px] gap-2' onClose={() => setIsShowHostInput(false)}>
|
||||
<Input
|
||||
autoFocus
|
||||
placeholder='Enter host of Elementum'
|
||||
value={host}
|
||||
onChange={({ target: { value } }) => setHost(value)}
|
||||
onKeyDown={({ key }) => key === 'Enter' && setIsShowHostInput(false)}
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
))}
|
||||
{isLoading && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={4}>
|
||||
<div className='h-40 w-full flex items-center justify-center'>
|
||||
<Loader className='animate-spin' />
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{isFetched && !torrents?.length && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={4}>
|
||||
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
|
||||
Nothing was found
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export const showTorrentsModal = create(Torrents);
|
||||
|
||||
export default Torrents;
|
||||
@@ -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<void> {
|
||||
trailerKey?: string;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const Trailer: FC<Props> = ({ trailerKey, onClose }) => {
|
||||
const Trailer: FC<Props> = ({ trailerKey, onResolve, isOpen }) => {
|
||||
if (!trailerKey) return;
|
||||
|
||||
return (
|
||||
trailerKey && (
|
||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && onClose()}>
|
||||
<DialogContent className='block p-0 min-h-[400px] border-none aspect-w-16 aspect-h-9' onClose={onClose}>
|
||||
<iframe
|
||||
allow='autoplay'
|
||||
className='border-none rounded-lg'
|
||||
width='100%'
|
||||
height='100%'
|
||||
src={`//www.youtube.com/embed/${trailerKey}?autoplay=1`}
|
||||
allowFullScreen
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
<Modal
|
||||
className='block p-0 min-h-[400px] border-none aspect-w-16 aspect-h-9'
|
||||
onClose={() => onResolve()}
|
||||
isOpen={isOpen}
|
||||
>
|
||||
<iframe
|
||||
allow='autoplay'
|
||||
className='border-none rounded-lg'
|
||||
width='100%'
|
||||
height='100%'
|
||||
src={`//www.youtube.com/embed/${trailerKey}?autoplay=1`}
|
||||
allowFullScreen
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export const showTrailerModal = create(Trailer);
|
||||
|
||||
export default Trailer;
|
||||
+25
-26
@@ -1,56 +1,55 @@
|
||||
import * as React from 'react'
|
||||
import { Slot } from '@radix-ui/react-slot'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
import * as React from 'react';
|
||||
import { useRef, useState } from 'react';
|
||||
import { cva, type VariantProps } from 'class-variance-authority';
|
||||
import { HTMLMotionProps, motion } from 'framer-motion';
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const buttonVariants = cva(
|
||||
'inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
|
||||
destructive:
|
||||
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
|
||||
outline:
|
||||
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
|
||||
secondary:
|
||||
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
||||
default: 'bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm active:shadow',
|
||||
destructive: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',
|
||||
outline: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
|
||||
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
||||
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
||||
link: 'text-primary underline-offset-4 hover:underline',
|
||||
link: 'text-primary underline-offset-4 hover:underline'
|
||||
},
|
||||
size: {
|
||||
default: 'h-10 px-4 py-2',
|
||||
sm: 'h-9 rounded-md px-3',
|
||||
lg: 'h-11 rounded-md px-8',
|
||||
icon: 'h-10 w-10',
|
||||
},
|
||||
icon: 'h-10 w-10'
|
||||
}
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
size: 'default',
|
||||
},
|
||||
size: 'default'
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean
|
||||
asChild?: boolean;
|
||||
}
|
||||
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : 'button'
|
||||
const Button = React.forwardRef<HTMLButtonElement, HTMLMotionProps<'button'> & Pick<ButtonProps, 'size' | 'variant'>>(
|
||||
({ className, variant, size, ...props }, ref) => {
|
||||
return (
|
||||
<Comp
|
||||
<motion.button
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
{...props}
|
||||
onClick={undefined}
|
||||
onTap={(e) => props.onClick?.(e as unknown as React.MouseEvent<HTMLButtonElement, MouseEvent>)}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
)
|
||||
Button.displayName = 'Button'
|
||||
);
|
||||
Button.displayName = 'Button';
|
||||
|
||||
export { Button, buttonVariants }
|
||||
export { Button, buttonVariants };
|
||||
+65
-55
@@ -1,32 +1,35 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import { useState } from 'react';
|
||||
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
||||
import { AnimatePresence, motion, useDragControls } from 'framer-motion';
|
||||
import { GripHorizontal } from 'lucide-react';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const Dialog = DialogPrimitive.Root;
|
||||
|
||||
const DialogTrigger = DialogPrimitive.Trigger;
|
||||
|
||||
const DialogPortal = ({ className, ...props }: DialogPrimitive.DialogPortalProps) => (
|
||||
<DialogPrimitive.Portal className={cn(className)} {...props} />
|
||||
);
|
||||
const DialogPortal = ({ ...props }: DialogPrimitive.DialogPortalProps) => <DialogPrimitive.Portal {...props} />;
|
||||
DialogPortal.displayName = DialogPrimitive.Portal.displayName;
|
||||
|
||||
const transition = { duration: 0.35, type: 'spring', bounce: 0 };
|
||||
|
||||
const DialogOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Overlay
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'fixed inset-0 z-50 bg-black/70 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
<DialogPrimitive.Overlay ref={ref} {...props}>
|
||||
<motion.div
|
||||
onScroll={props.onScroll}
|
||||
className={cn('fixed inset-0 z-50 transform-gpu backdrop-brightness-50 select-none', className)}
|
||||
transition={transition}
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
>
|
||||
{props?.children}
|
||||
</motion.div>
|
||||
</DialogPrimitive.Overlay>
|
||||
));
|
||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||
|
||||
@@ -34,54 +37,61 @@ const DialogContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & { onClose?: () => void }
|
||||
>(({ className, children, ...props }, ref) => {
|
||||
const controls = useDragControls();
|
||||
return (
|
||||
<DialogPortal>
|
||||
<DialogOverlay className='overflow-auto flex justify-center'>
|
||||
<DialogPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'absolute top-[20vh] max-w-[1000px] w-[calc(100%-24px)] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 rounded-xl',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
<DialogOverlay className='overflow-auto flex justify-center select-none'>
|
||||
<motion.div
|
||||
className='absolute top-[20vh] max-w-[1000px] w-[calc(100%-24px)] select-none'
|
||||
transition={transition}
|
||||
initial={{ top: '100vh' }}
|
||||
animate={{ top: '20vh' }}
|
||||
exit={{ top: '100vh' }}
|
||||
drag='y'
|
||||
dragConstraints={{ top: 0, bottom: 300 }}
|
||||
onDragEnd={(_, info) => info.offset.y > 100 && props.onClose?.()}
|
||||
dragListener={false}
|
||||
dragControls={controls}
|
||||
dragElastic={0.5}
|
||||
>
|
||||
{children}
|
||||
<div className='absolute w-full block h-[20vh] pointer-events-none' />
|
||||
</DialogPrimitive.Content>
|
||||
<DialogPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn('gap-4 border bg-background p-6 shadow-lg rounded-xl relative', className)}
|
||||
{...props}
|
||||
>
|
||||
<motion.div
|
||||
className='w-full h-10 flex p-2 justify-center cursor-grab absolute top-[-36px] z-10'
|
||||
onPointerDown={(e) => controls.start(e)}
|
||||
>
|
||||
<GripHorizontal color='white' />
|
||||
</motion.div>
|
||||
{children}
|
||||
<div className='absolute w-full block h-[20vh] pointer-events-none' />
|
||||
</DialogPrimitive.Content>
|
||||
</motion.div>
|
||||
</DialogOverlay>
|
||||
</DialogPortal>
|
||||
);
|
||||
});
|
||||
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
||||
|
||||
const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn('flex flex-col space-y-1.5 text-center sm:text-left', className)} {...props} />
|
||||
);
|
||||
DialogHeader.displayName = 'DialogHeader';
|
||||
const Modal: React.FC<{
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
}> = ({ children, onClose, isOpen, className }) => {
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{isOpen && (
|
||||
<Dialog defaultOpen={true} onOpenChange={onClose}>
|
||||
<DialogContent forceMount className={className} onClose={onClose}>
|
||||
{children}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
};
|
||||
|
||||
const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn('flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', className)} {...props} />
|
||||
);
|
||||
DialogFooter.displayName = 'DialogFooter';
|
||||
|
||||
const DialogTitle = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn('text-lg font-semibold leading-none tracking-tight', className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
||||
|
||||
const DialogDescription = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
|
||||
));
|
||||
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
||||
|
||||
export { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger };
|
||||
export { Dialog, DialogContent, Modal };
|
||||
@@ -29,7 +29,7 @@ const TabsTrigger = React.forwardRef<
|
||||
<TabsPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm',
|
||||
'inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
Reference in new issue
Block a user