feat: animations
This commit is contained in:
1 parent
e4788ae384
commit
7b55619cf5
16 files changed
+643
-320
No files matched your search
@@ -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;
|
||||
Reference in new issue
Block a user