feat: series
This commit is contained in:
1 parent
b2eef6c494
commit
1e31520c92
25 files changed
+435
-223
No files matched your search
@@ -33,12 +33,12 @@ const Card: FC<Props> = ({ movie, onClick, fit }) => {
|
||||
>
|
||||
<motion.div className='absolute top-0 left-0 flex flex-col w-full h-full mx-auto bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg'>
|
||||
<motion.div onTap={onClick} className='flex w-full h-full'>
|
||||
<Poster title={movie.title} size={100} poster={movie.poster_path} />
|
||||
<Poster title={movie?.name || movie.title} size={100} poster={movie.poster_path} />
|
||||
</motion.div>
|
||||
<div className='absolute left-0 top-0 w-full h-20 bg-gradient-to-t from-transparent to-black opacity-75 rounded-t-lg'>
|
||||
<div className='h-full w-full mx-auto pt-1 px-3 text-white'>
|
||||
<div className='grid items-center grid-cols-[1fr_50px]'>
|
||||
<Title key={movie.title} title={movie.title} />
|
||||
<Title key={movie?.name || movie.title} title={movie?.name || movie.title} />
|
||||
{movie.release_date && (
|
||||
<span className='flex justify-end text-lg font-semibold'>
|
||||
{new Date(movie.release_date).getFullYear()}
|
||||
|
||||
+36
-21
@@ -1,4 +1,4 @@
|
||||
import { FC, Fragment, useLayoutEffect, useState } from 'react';
|
||||
import { FC, Fragment, useLayoutEffect, useMemo, useState } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
|
||||
import Card from '@/components/Movie/Card';
|
||||
@@ -11,6 +11,7 @@ interface Props {
|
||||
fetchNextPage?: () => void;
|
||||
withBottomGap?: boolean;
|
||||
onPreviewClose?: () => void;
|
||||
type?: ShowType;
|
||||
}
|
||||
|
||||
const container = {
|
||||
@@ -30,7 +31,14 @@ const item = {
|
||||
}
|
||||
};
|
||||
|
||||
const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, withBottomGap = true, onPreviewClose }) => {
|
||||
const List: FC<Props> = ({
|
||||
pages,
|
||||
hasNextPage,
|
||||
fetchNextPage,
|
||||
withBottomGap = true,
|
||||
onPreviewClose,
|
||||
type = 'movie'
|
||||
}) => {
|
||||
const [loader, setLoader] = useState<HTMLLIElement>();
|
||||
|
||||
useLayoutEffect(() => {
|
||||
@@ -52,34 +60,41 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, withBottomGap = tr
|
||||
return () => observer.disconnect();
|
||||
}, [fetchNextPage, loader, hasNextPage]);
|
||||
|
||||
const shows = useMemo(
|
||||
() =>
|
||||
pages?.reduce((shows, page) => {
|
||||
shows.push(...filterUnknownMovies(page.results));
|
||||
return shows;
|
||||
}, [] as Movie[]) || [],
|
||||
[pages]
|
||||
);
|
||||
|
||||
if (!shows.length) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<motion.ul
|
||||
className='flex gap-3 flex-wrap justify-center grow'
|
||||
className='flex gap-3 flex-wrap justify-center grow empty:hidden'
|
||||
variants={container}
|
||||
initial={pages.length === 1 ? 'hidden' : false}
|
||||
animate='visible'
|
||||
>
|
||||
{pages.map((page) => (
|
||||
<Fragment key={page.page}>
|
||||
{filterUnknownMovies(page.results)?.map((movie, index, array) => {
|
||||
const isAnchor = Math.round(array.length / 2) === index;
|
||||
{shows?.map((movie, index, array) => {
|
||||
const isAnchor = Math.round(array.length / 2) === index;
|
||||
|
||||
return (
|
||||
<motion.li
|
||||
key={movie.id}
|
||||
variants={item}
|
||||
className='flex xs:w-auto w-full cursor-pointer'
|
||||
ref={isAnchor ? (element) => setLoader(element!) : undefined}
|
||||
>
|
||||
<Card fit movie={movie} onClick={() => showPreviewModal({ movie, onClose: onPreviewClose })} />
|
||||
</motion.li>
|
||||
);
|
||||
})}
|
||||
</Fragment>
|
||||
))}
|
||||
return (
|
||||
<motion.li
|
||||
key={movie.id}
|
||||
variants={item}
|
||||
className='flex xs:w-auto w-full cursor-pointer'
|
||||
ref={isAnchor ? (element) => setLoader(element!) : undefined}
|
||||
>
|
||||
<Card fit movie={movie} onClick={() => showPreviewModal({ movie, onClose: onPreviewClose, type })} />
|
||||
</motion.li>
|
||||
);
|
||||
})}
|
||||
</motion.ul>
|
||||
{withBottomGap && <div className='h-4 w-full' />}
|
||||
{withBottomGap && <div className='h-2 w-full' />}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -10,14 +10,15 @@ import ToggleTrailer from '../../components/Trailer';
|
||||
interface Props {
|
||||
movie: Movie;
|
||||
onClose?: () => void;
|
||||
type?: ShowType;
|
||||
}
|
||||
|
||||
export default function Actions({ onClose, movie }: Props) {
|
||||
export default function Actions({ onClose, movie, type }: Props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<ToggleTrailer movieId={movie?.id}>
|
||||
<ToggleTrailer type={type} movieId={movie?.id}>
|
||||
{({ onPlay, disabled }) => (
|
||||
<Button className='h-8 flex-grow w-[50%]' onClick={onPlay} disabled={disabled}>
|
||||
Trailer
|
||||
@@ -26,14 +27,21 @@ export default function Actions({ onClose, movie }: Props) {
|
||||
</ToggleTrailer>
|
||||
<Button
|
||||
className='h-8 flex-grow w-[50%]'
|
||||
onClick={() => showTorrentsModal({ title: movie.title, year: new Date(movie.release_date).getFullYear() })}
|
||||
onClick={() =>
|
||||
showTorrentsModal({
|
||||
title: movie?.name || movie.title,
|
||||
year: new Date(movie.first_air_date || movie.release_date).getFullYear()
|
||||
})
|
||||
}
|
||||
>
|
||||
Torrents
|
||||
</Button>
|
||||
<Button
|
||||
className='h-8 flex-grow w-[50%]'
|
||||
onClick={() => {
|
||||
router.push(`/similar?movieId=${movie.id}&title=${encodeURIComponent(movie.title)}`);
|
||||
router.push(
|
||||
`/similar?movieId=${movie.id}&title=${encodeURIComponent(movie?.name || movie.title)}&type=${type}`
|
||||
);
|
||||
onClose?.();
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -19,9 +19,10 @@ interface Props {
|
||||
onClose?: () => void;
|
||||
children?: ReactNode;
|
||||
card?: ReactNode;
|
||||
type?: ShowType;
|
||||
}
|
||||
|
||||
const Preview: FC<Props> = ({ movie, className, onClose, children, card, fit }) => {
|
||||
const Preview: FC<Props> = ({ movie, className, onClose, children, card, fit, type = 'movie' }) => {
|
||||
if (!movie) return null;
|
||||
|
||||
return (
|
||||
@@ -35,7 +36,7 @@ const Preview: FC<Props> = ({ movie, className, onClose, children, card, fit })
|
||||
<div className='flex flex-col grow'>
|
||||
{children && <div className='flex hover-none:hidden w-full max-sm:mb-0 mb-2 gap-2'>{children}</div>}
|
||||
<div className='flex w-full gap-2'>
|
||||
<Actions movie={movie} onClose={onClose} />
|
||||
<Actions type={type} movie={movie} onClose={onClose} />
|
||||
</div>
|
||||
<Separator className='my-2' />
|
||||
<p key={movie.id} className='leading-7'>
|
||||
@@ -43,15 +44,16 @@ const Preview: FC<Props> = ({ movie, className, onClose, children, card, fit })
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Credits movieId={movie.id} onPersonClick={onClose} />
|
||||
<Credits type={type} movieId={movie.id} onPersonClick={onClose} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const showPreviewModal = create(({ onResolve, onClose, movie }: Props & InstanceProps<void>) => (
|
||||
export const showPreviewModal = create(({ onResolve, onClose, movie, type = 'movie' }: Props & InstanceProps<void>) => (
|
||||
<Modal className='block p-0' onClose={onResolve}>
|
||||
<Preview
|
||||
fit
|
||||
type={type}
|
||||
movie={movie}
|
||||
className='border-none'
|
||||
onClose={() => {
|
||||
|
||||
@@ -11,6 +11,7 @@ import useCredits from '@/app/(site)/useCredits';
|
||||
interface Props {
|
||||
movieId: number;
|
||||
onPersonClick?: (id: string) => void;
|
||||
type?: ShowType;
|
||||
}
|
||||
|
||||
const container = {
|
||||
@@ -30,9 +31,9 @@ const item = {
|
||||
}
|
||||
};
|
||||
|
||||
const Credits: FC<Props> = ({ movieId, onPersonClick }) => {
|
||||
const Credits: FC<Props> = ({ movieId, onPersonClick, type = 'movie' }) => {
|
||||
const router = useRouter();
|
||||
const { data: credits } = useCredits({ movieId });
|
||||
const { data: credits } = useCredits({ movieId, type });
|
||||
|
||||
return (
|
||||
Boolean(credits?.length) && (
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useHost, useSetHost } from '@/hooks/useMagnetHosts';
|
||||
|
||||
const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onReject }) => {
|
||||
const host = useHost();
|
||||
const setHost = useSetHost();
|
||||
return (
|
||||
<Modal className='p-2 max-w-[200px] m-auto' onClose={onReject}>
|
||||
<Input
|
||||
autoFocus
|
||||
placeholder='Enter host of Elementum'
|
||||
value={host}
|
||||
className='focus-visible:ring-0'
|
||||
onChange={({ target: { value } }) => setHost(value)}
|
||||
onKeyDown={({ key }) => key === 'Enter' && onResolve(host)}
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
export default showHostManagerModal;
|
||||
@@ -1,8 +1,6 @@
|
||||
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, useAtomValue } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
import { Cast, Loader, Magnet } from 'lucide-react';
|
||||
|
||||
import useTorrents from '@/app/(site)/useTorrents';
|
||||
@@ -10,7 +8,9 @@ import { Modal } from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { Toggle } from '@/components/ui/toggle';
|
||||
import { useCastMagnet, useHost, useSetHost } from '@/hooks/useMagnetHosts';
|
||||
import { ORDER } from '@/lib/api/parsers/pirate-bay';
|
||||
import showHostManagerModal from './HostManager';
|
||||
|
||||
interface Props extends InstanceProps<void> {
|
||||
title: string;
|
||||
@@ -49,26 +49,8 @@ const TableHeadSortable = ({
|
||||
);
|
||||
};
|
||||
|
||||
const hostAtom = atomWithStorage<string>('magnet-host', '');
|
||||
|
||||
const showHostManagerModal = create(({ onResolve }) => {
|
||||
const [host, setHost] = useAtom(hostAtom);
|
||||
return (
|
||||
<Modal className='p-2 max-w-[200px] m-auto' onClose={onResolve}>
|
||||
<Input
|
||||
autoFocus
|
||||
placeholder='Enter host of Elementum'
|
||||
value={host}
|
||||
className='focus-visible:ring-0'
|
||||
onChange={({ target: { value } }) => setHost(value)}
|
||||
onKeyDown={({ key }) => key === 'Enter' && onResolve()}
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
||||
const hosts = useAtomValue(hostAtom);
|
||||
const host = useHost();
|
||||
const [sorting, setSorting] = useState<Sorting>({ by: ORDER.seeders });
|
||||
const [withYear, setWithYear] = useState(true);
|
||||
|
||||
@@ -78,14 +60,7 @@ const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
||||
isFetched
|
||||
} = useTorrents({ query: withYear ? `${title} ${year || ''}` : title, order: sorting.by });
|
||||
|
||||
const handleCast = (magnet: string) => (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
|
||||
event.preventDefault();
|
||||
|
||||
hosts.split(',').forEach((host) => {
|
||||
const link = window.open(`http://${host}:65220/playuri?uri=${magnet}`, '_blank');
|
||||
setTimeout(() => link?.close(), 1000);
|
||||
});
|
||||
};
|
||||
const cast = useCastMagnet();
|
||||
|
||||
return (
|
||||
<Modal className='p-0' onClose={onResolve}>
|
||||
@@ -123,9 +98,12 @@ const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
||||
<TableCell className='text-center p-2'>{torrent.seeders}</TableCell>
|
||||
<TableCell className='text-center p-1'>
|
||||
<div className='flex gap-2 m-auto justify-center'>
|
||||
{hosts ? (
|
||||
{host ? (
|
||||
<a
|
||||
onClick={handleCast(torrent.magnet!)}
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
cast(torrent.magnet!);
|
||||
}}
|
||||
className='flex items-center justify-center h-8 w-8 border rounded-lg'
|
||||
>
|
||||
<Cast size={20} />
|
||||
|
||||
@@ -11,6 +11,7 @@ import { Modal } from '@/components/ui/dialog';
|
||||
interface Props {
|
||||
movieId?: number;
|
||||
children?: ({ onPlay, disabled }: { onPlay: () => void; disabled: boolean }) => ReactNode;
|
||||
type?: ShowType;
|
||||
}
|
||||
|
||||
const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey, onResolve }) => {
|
||||
@@ -32,8 +33,8 @@ const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey
|
||||
|
||||
export const showTrailerModal = create(Trailer);
|
||||
|
||||
export default function ToggleTrailer({ movieId, children }: Props) {
|
||||
const { data: trailer, isFetched } = useTrailer({ movieId });
|
||||
export default function ToggleTrailer({ movieId, type = 'movie', children }: Props) {
|
||||
const { data: trailer, isFetched } = useTrailer({ movieId, type });
|
||||
|
||||
return children
|
||||
? children({ onPlay: () => showTrailerModal({ trailerKey: trailer?.key }), disabled: isFetched && !trailer })
|
||||
|
||||
Reference in new issue
Block a user