feat: favorite & watch lists
This commit is contained in:
1 parent
960a7a6242
commit
8858e47d38
51 files changed
+561
-290
No files matched your search
@@ -2,5 +2,6 @@ export const paths = [
|
||||
{ path: '/', title: 'Random' },
|
||||
{ path: '/popular', title: 'Popular' },
|
||||
{ path: '/top', title: 'Top rated' },
|
||||
{ path: '/favorites', title: 'Favorites' }
|
||||
{ path: '/favorites', title: 'Favorites' },
|
||||
{ path: '/watch-list', title: 'Watch list' }
|
||||
];
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { LogIn,LogOut, User as UserIcon, UserRound } from 'lucide-react';
|
||||
import { LogIn, LogOut, User as UserIcon, UserRound } from 'lucide-react';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
@@ -11,8 +11,8 @@ import {
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import useAccount from '@/hooks/useAccount';
|
||||
|
||||
import useAccount from './useAccount';
|
||||
import useAuth from './useAuth';
|
||||
import useLogOut from './useLogOut';
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { account } from '@/api';
|
||||
import { useSession } from '@/hooks/useSession';
|
||||
|
||||
const KEY = ['account'];
|
||||
|
||||
const useAccount = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const session = useSession();
|
||||
|
||||
const query = useQuery({
|
||||
enabled: Boolean(session),
|
||||
staleTime: Infinity,
|
||||
notifyOnChangeProps: ['data'],
|
||||
queryKey: KEY,
|
||||
queryFn: () => account()
|
||||
});
|
||||
|
||||
if (session === null) {
|
||||
queryClient.removeQueries({ queryKey: KEY });
|
||||
queryClient.resetQueries({ queryKey: KEY });
|
||||
}
|
||||
|
||||
return session ? query.data : undefined;
|
||||
};
|
||||
|
||||
export default useAccount;
|
||||
@@ -16,7 +16,7 @@ interface Props {
|
||||
const Header: FC<Props> = ({ className }) => (
|
||||
<header
|
||||
className={cn(
|
||||
'flex justify-center bg-background/95 py-2 backdrop-blur supports-[backdrop-filter]:bg-background/60',
|
||||
'flex justify-center bg-background/95 md:py-2 py-1 backdrop-blur supports-[backdrop-filter]:bg-background/60',
|
||||
className
|
||||
)}
|
||||
>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { FC } from 'react';
|
||||
import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso';
|
||||
|
||||
import Poster from '@/components/Poster';
|
||||
import { showPreviewModal } from '@/components/Preview';
|
||||
import Card from '@/components/Show';
|
||||
|
||||
interface Props {
|
||||
shows: Show[];
|
||||
@@ -18,7 +18,7 @@ const components: VirtuosoGridProps<Movie, { shows: Show[]; onClick: (show: Show
|
||||
|
||||
if (!show) return null;
|
||||
|
||||
return <Card show={show} onClick={() => onClick?.(show)} />;
|
||||
return <Poster show={show} onClick={() => onClick?.(show)} />;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
|
||||
import { useMutateShowState } from '@/hooks/useShowState';
|
||||
|
||||
interface Props {
|
||||
show: Show;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
const Handlers: FC<Props> = ({ onClick, show }) => {
|
||||
const { mutate } = useMutateShowState(show);
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={onClick}
|
||||
onDoubleClick={() => mutate({ list: 'favorite', value: true })}
|
||||
className='absolute left-0 top-0 size-full'
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default Handlers;
|
||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,42 @@
|
||||
import { DetailedHTMLProps, FC, HTMLAttributes } from 'react';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import Handlers from './components/Handlers';
|
||||
|
||||
interface Props {
|
||||
show?: Show;
|
||||
onClick?: () => void;
|
||||
className?: string;
|
||||
rounded?: string;
|
||||
containerProps?: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
||||
}
|
||||
|
||||
const Poster: FC<Props> = ({ show, onClick, className, rounded, containerProps }) => {
|
||||
if (!show) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
{...(containerProps || {})}
|
||||
className={cn(
|
||||
'card-aspect-ratio relative bg-card text-card-foreground overflow-hidden rounded-lg text-lg',
|
||||
className,
|
||||
rounded
|
||||
)}
|
||||
>
|
||||
<div className='flex size-full'>
|
||||
<img className={cn('size-full rounded-lg object-cover', rounded)} src={show.poster} alt={show.title} />
|
||||
</div>
|
||||
<div
|
||||
className={cn(
|
||||
'absolute left-0 top-0 flex size-full flex-col justify-between rounded-md bg-vignette p-2 text-white',
|
||||
rounded
|
||||
)}
|
||||
>
|
||||
<Handlers show={show} onClick={onClick} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Poster;
|
||||
@@ -1,46 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
|
||||
import showTorrentsModal from '@/components/Show/components/Torrents';
|
||||
import ToggleTrailer from '@/components/Show/components/Trailer';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
interface Props {
|
||||
show: Show & Partial<Details>;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
const Actions = ({ onClose, show }: Props) => (
|
||||
<>
|
||||
<ToggleTrailer showType={show.type} showId={show.id}>
|
||||
{({ onPlay, disabled }) => (
|
||||
<Button className='h-8 w-1/2 grow' onClick={onPlay} disabled={disabled}>
|
||||
Trailer
|
||||
</Button>
|
||||
)}
|
||||
</ToggleTrailer>
|
||||
<Button
|
||||
className='h-8 w-1/2 grow'
|
||||
onClick={() =>
|
||||
showTorrentsModal({
|
||||
imdbID: show.imdb_id!,
|
||||
title: show.title,
|
||||
backdrop: show.backdrop,
|
||||
year: new Date(show.release).getFullYear()
|
||||
})
|
||||
}
|
||||
>
|
||||
Torrents
|
||||
</Button>
|
||||
<Link
|
||||
className='flex w-1/2'
|
||||
href={`/similar?id=${show.id}&title=${encodeURIComponent(show.title)}&type=${show.type}`}
|
||||
onClick={onClose}
|
||||
>
|
||||
<Button className='h-8 grow'>Similar</Button>
|
||||
</Link>
|
||||
</>
|
||||
);
|
||||
|
||||
export default Actions;
|
||||
@@ -0,0 +1,84 @@
|
||||
'use client';
|
||||
|
||||
import { Bookmark, Copy, Heart, Play, Star } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
|
||||
import showTorrentsModal from '@/components/Preview/components/Torrents';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import useShowState, { useMutateShowState } from '@/hooks/useShowState';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface Props {
|
||||
show: Show & Partial<Details>;
|
||||
className: string;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
const Actions = ({ onClose, show, className }: Props) => {
|
||||
const state = useShowState({ showId: show.id, showType: show.type });
|
||||
const toggle = useMutateShowState(show);
|
||||
|
||||
const groupClassName = 'flex bg-input gap-[1px] rounded-md md:flex-grow-0 flex-grow';
|
||||
const leftClassName = 'h-8 gap-1 flex-grow border-r-0 rounded-none rounded-l-md md:px-3 px-2';
|
||||
const rightClassName = 'h-8 gap-1 flex-grow border-l-0 rounded-none rounded-r-md md:px-3 px-2';
|
||||
|
||||
return (
|
||||
<div className={cn('flex gap-2 flex-wrap md:flex-grow-0 flex-grow', className)}>
|
||||
<div className={cn(groupClassName, 'pointer-events-none')}>
|
||||
<Button className={leftClassName} variant='outline'>
|
||||
<Star size={14} />
|
||||
</Button>
|
||||
<Button className={rightClassName} variant='outline'>
|
||||
{show.rating.toFixed(1)}
|
||||
</Button>
|
||||
</div>
|
||||
<div className={groupClassName}>
|
||||
<Button
|
||||
className={leftClassName}
|
||||
variant='outline'
|
||||
disabled={toggle.list === 'favorite' && toggle.isPending}
|
||||
onClick={() => toggle.mutate({ list: 'favorite', value: !state?.favorite })}
|
||||
>
|
||||
<Heart size={14} className={cn({ 'fill-secondary-foreground': state?.favorite })} />
|
||||
</Button>
|
||||
<Button
|
||||
className={rightClassName}
|
||||
variant='outline'
|
||||
disabled={toggle.list === 'watchlist' && toggle.isPending}
|
||||
onClick={() => toggle.mutate({ list: 'watchlist', value: !state?.watchlist })}
|
||||
>
|
||||
<Bookmark size={14} className={cn({ 'fill-secondary-foreground': state?.watchlist })} />
|
||||
</Button>
|
||||
</div>
|
||||
<div className={cn(groupClassName, 'gap-0')}>
|
||||
<Link
|
||||
className='flex grow'
|
||||
href={`/similar?id=${show.id}&title=${encodeURIComponent(show.title)}&type=${show.type}`}
|
||||
onClick={onClose}
|
||||
>
|
||||
<Button className={leftClassName} variant='outline'>
|
||||
<Copy size={14} />
|
||||
Similar
|
||||
</Button>
|
||||
</Link>
|
||||
<Button
|
||||
className={cn(rightClassName, 'bg-red-600')}
|
||||
variant='destructive'
|
||||
onClick={() =>
|
||||
showTorrentsModal({
|
||||
imdbID: show.imdb_id!,
|
||||
title: show.title,
|
||||
backdrop: show.backdrop,
|
||||
year: new Date(show.release).getFullYear()
|
||||
})
|
||||
}
|
||||
>
|
||||
<Play size={15} />
|
||||
Watch
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Actions;
|
||||
File renamed without changes.
File renamed without changes.
+2
-1
@@ -2,7 +2,8 @@ import { create, InstanceProps } from 'react-modal-promise';
|
||||
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { usePrefix, useSetPrefix } from '@/hooks/useMagnetHosts';
|
||||
|
||||
import { usePrefix, useSetPrefix } from '../../hooks/useMagnetHosts';
|
||||
|
||||
const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onReject }) => {
|
||||
const prefix = usePrefix();
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -35,7 +35,7 @@ const showPlayer = create(({ onResolve, magnet, backdrop, title }: Props) => {
|
||||
}
|
||||
|
||||
if (isFetched && !videos.length) {
|
||||
toast({ description: 'This torrent doesn\'t contain any compatible video files' });
|
||||
toast({ description: 'This torrent doesn’t contain any compatible video files' });
|
||||
onResolve();
|
||||
}
|
||||
|
||||
File renamed without changes.
File renamed without changes.
+1
-1
@@ -4,9 +4,9 @@ import { Cast, Copy, ListVideo, Magnet, Play } from 'lucide-react';
|
||||
import { Sort } from '@/api/parsers';
|
||||
import { Quality } from '@/api/parsers/yts/models';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { useCastMagnet, usePrefix } from '@/hooks/useMagnetHosts';
|
||||
|
||||
import { providers } from '../../constants';
|
||||
import { useCastMagnet, usePrefix } from '../../hooks/useMagnetHosts';
|
||||
import showHostManagerModal from '../HostManager';
|
||||
import showPlayer from '../Player';
|
||||
import TableHeadSortable from '../TableHeadSortable';
|
||||
File renamed without changes.
@@ -0,0 +1,31 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
|
||||
import showHostManagerModal from '@/components/Preview/components/Torrents/components/HostManager';
|
||||
|
||||
const magnetPrefixAtom = atomWithStorage<string>('magnet-prefix', 'http://{host}:65220/playuri?uri=', undefined, {
|
||||
unstable_getOnInit: true
|
||||
});
|
||||
|
||||
export const usePrefix = () => useAtomValue(magnetPrefixAtom);
|
||||
|
||||
export const useSetPrefix = () => useSetAtom(magnetPrefixAtom);
|
||||
|
||||
export const useCastMagnet = () => {
|
||||
const prefix = usePrefix();
|
||||
|
||||
return useCallback(
|
||||
(magnet: string) => {
|
||||
const open = (prefix: string) => {
|
||||
const link = window.open(`${prefix}${magnet}`, '_blank');
|
||||
setTimeout(() => link?.close(), 1000);
|
||||
};
|
||||
|
||||
if (!prefix || prefix.includes('{host}')) return showHostManagerModal().then(open);
|
||||
|
||||
return Promise.resolve(open(prefix));
|
||||
},
|
||||
[prefix]
|
||||
);
|
||||
};
|
||||
+1
-1
@@ -60,7 +60,7 @@ const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }:
|
||||
<Modal className='rounded-xl p-0 pb-1' onClose={onResolve}>
|
||||
<div className='grid grid-cols-[1fr_auto] items-center gap-3 p-2'>
|
||||
<span className='truncate text-base'>{title}</span>
|
||||
<Button className='h-6 p-2' variant={withYear ? 'default' : 'ghost'} onClick={() => setWithYear((w) => w)}>
|
||||
<Button className='h-6 p-2' variant={withYear ? 'default' : 'ghost'} onClick={() => setWithYear((w) => !w)}>
|
||||
{year}
|
||||
</Button>
|
||||
</div>
|
||||
File renamed without changes.
@@ -3,11 +3,10 @@
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
|
||||
import Poster from '@/components/Poster';
|
||||
import Credits from '@/components/Preview/components/Credits';
|
||||
import useDetails from '@/components/Preview/useDetails';
|
||||
import Card from '@/components/Show';
|
||||
import Credits from '@/components/Show/components/Credits';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import Actions from './components/Actions';
|
||||
@@ -16,30 +15,47 @@ interface Props {
|
||||
show?: Show;
|
||||
className?: string;
|
||||
onClose?: () => void;
|
||||
children?: ReactNode;
|
||||
card?: ReactNode;
|
||||
poster?: ReactNode;
|
||||
}
|
||||
|
||||
const Preview: FC<Props> = ({ show: baseShow, className, onClose, children, card }) => {
|
||||
const Preview: FC<Props> = ({ show: baseShow, className, onClose, poster }) => {
|
||||
const { data: detailedShow } = useDetails({ showId: baseShow?.id, showType: baseShow?.type });
|
||||
|
||||
if (!baseShow) return null;
|
||||
|
||||
const show: (Show & Partial<Details>) | undefined = detailedShow || baseShow;
|
||||
|
||||
const isModal = Boolean(onClose);
|
||||
|
||||
return (
|
||||
<div className={cn('flex flex-col md:flex-row gap-2 rounded-xl', { 'p-2': Boolean(onClose) }, className)}>
|
||||
{card || <Card className='mx-auto' show={show} />}
|
||||
<div className='flex grow flex-col'>
|
||||
{children && <div className='mb-2 flex w-full gap-2 hover-none:hidden max-sm:mb-0'>{children}</div>}
|
||||
<div className='flex w-full gap-2'>
|
||||
<Actions show={show} onClose={onClose} />
|
||||
<div
|
||||
className={cn(
|
||||
'flex flex-col md:flex-row gap-2 rounded-xl',
|
||||
{ 'md:pl-0 md:pt-0 md:pb-0 pl-2 pt-2 pb-2 pr-2 border-none gap-0': isModal },
|
||||
className
|
||||
)}
|
||||
>
|
||||
{poster || <Poster className='mx-auto' rounded='md:rounded-none md:rounded-l-xl' show={show} />}
|
||||
<div className={cn('flex grow flex-col', { 'md:pb-2 md:pl-2 pb-0 pl-0 pt-2': isModal })}>
|
||||
<span className='order-3 mb-4 text-3xl md:order-1 md:line-clamp-2'>{show.title}</span>
|
||||
|
||||
<div className='order-3 mb-4 flex w-full flex-wrap gap-5 whitespace-nowrap text-sm md:order-2'>
|
||||
<span>{new Date(show.release).getFullYear()}</span>
|
||||
{show.runtime && <span>{show.runtime} minutes</span>}
|
||||
<span>
|
||||
{show.genres
|
||||
?.slice(0, 3)
|
||||
.map(({ name }) => name)
|
||||
.join(' | ')}
|
||||
</span>
|
||||
</div>
|
||||
<Separator className='my-2' />
|
||||
<p key={show.id} className='mb-3 leading-7'>
|
||||
|
||||
<Actions className='order-1 mb-4 mt-1 md:order-2 md:mt-0' show={show} onClose={onClose} />
|
||||
|
||||
<p key={show.id} className='order-4 md:order-4 md:line-clamp-3' title={show.overview}>
|
||||
{show.overview}
|
||||
</p>
|
||||
<div className='mt-auto grid grid-cols-1 rounded-lg'>
|
||||
<div className='order-5 mt-5 grid grid-cols-1 rounded-lg md:order-5 md:mt-auto'>
|
||||
<Credits showType={show.type} showId={show.id} onPersonClick={onClose} />
|
||||
</div>
|
||||
</div>
|
||||
@@ -48,10 +64,9 @@ const Preview: FC<Props> = ({ show: baseShow, className, onClose, children, card
|
||||
};
|
||||
|
||||
export const showPreviewModal = create(({ onResolve, onClose, show }: Props & InstanceProps<void>) => (
|
||||
<Modal className='block p-0' onClose={onResolve}>
|
||||
<Modal className='block max-w-[932px] p-0' onClose={onResolve}>
|
||||
<Preview
|
||||
show={show}
|
||||
className='border-none'
|
||||
onClose={() => {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
onClose?.();
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
import { FC, ForwardedRef, forwardRef, useLayoutEffect, useRef } from 'react';
|
||||
import { Virtuoso, VirtuosoProps } from 'react-virtuoso';
|
||||
|
||||
import Poster from '@/components/Poster';
|
||||
import ScrollNavigation from '@/components/ScrollNavigation';
|
||||
import Card from '@/components/Show';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const components: VirtuosoProps<Show, (index: number) => void>['components'] = {
|
||||
@@ -36,7 +36,7 @@ const components: VirtuosoProps<Show, (index: number) => void>['components'] = {
|
||||
|
||||
return (
|
||||
<div {...props} ref={ref} className='snap-start'>
|
||||
<Card show={item} />
|
||||
<Poster show={item} />
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -12,7 +12,7 @@ const Random = () => {
|
||||
<Preview
|
||||
show={movie}
|
||||
className='rounded-md bg-background'
|
||||
card={<Carousel index={index} shows={movies} onIndexChange={onIndexChange} onEndReached={fetchNextPage} />}
|
||||
poster={<Carousel index={index} shows={movies} onIndexChange={onIndexChange} onEndReached={fetchNextPage} />}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import { Heart } from 'lucide-react';
|
||||
|
||||
import { useFavoriteToggle } from '@/app/(site)/favorites/useFavorites';
|
||||
import useMounted from '@/hooks/useMounted';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface Props {
|
||||
show: Show;
|
||||
}
|
||||
|
||||
const Favorite: FC<Props> = ({ show }) => {
|
||||
const isMounted = useMounted();
|
||||
const { isFavorite, toggle } = useFavoriteToggle(show);
|
||||
|
||||
return (
|
||||
<span
|
||||
onClick={toggle}
|
||||
className='cursor-pointer'
|
||||
title={isMounted && isFavorite ? 'Remove from favorites' : 'Add to favorite'}
|
||||
>
|
||||
<Heart className={cn(isMounted && isFavorite && 'fill-white')} size={20} />
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
export default Favorite;
|
||||
@@ -1,18 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
|
||||
import { useFavoriteToggle } from '@/app/(site)/favorites/useFavorites';
|
||||
|
||||
interface Props {
|
||||
show: Show;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
const Handlers: FC<Props> = ({ onClick, show }) => {
|
||||
const { toggle } = useFavoriteToggle(show);
|
||||
|
||||
return <div onClick={onClick} onDoubleClick={toggle} className='absolute left-0 top-0 size-full' />;
|
||||
};
|
||||
|
||||
export default Handlers;
|
||||
@@ -1,15 +0,0 @@
|
||||
import { FC } from 'react';
|
||||
import { Star } from 'lucide-react';
|
||||
|
||||
interface Props {
|
||||
rating?: number;
|
||||
}
|
||||
|
||||
const Rating: FC<Props> = ({ rating }) => (
|
||||
<span className='flex items-center'>
|
||||
<Star size={18} className='mr-1 fill-white' />
|
||||
<p className='mt-[3px]'>{rating?.toFixed(1)}</p>
|
||||
</span>
|
||||
);
|
||||
|
||||
export default Rating;
|
||||
@@ -1,48 +0,0 @@
|
||||
import { DetailedHTMLProps, FC, HTMLAttributes } from 'react';
|
||||
import Image from 'next/image';
|
||||
|
||||
import Rating from '@/components/Show/components/Rating';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import Favorite from './components/Favorite';
|
||||
import Handlers from './components/Handlers';
|
||||
|
||||
interface Props {
|
||||
show?: Show;
|
||||
onClick?: () => void;
|
||||
className?: string;
|
||||
containerProps?: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
||||
}
|
||||
|
||||
const Show: FC<Props> = ({ show, onClick, className, containerProps }) => {
|
||||
if (!show) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
{...(containerProps || {})}
|
||||
className={cn(
|
||||
'card-aspect-ratio relative bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg text-lg',
|
||||
className
|
||||
)}
|
||||
>
|
||||
<div className='flex size-full'>
|
||||
<img className='size-full rounded-lg object-cover' src={show.poster} alt={show.title} />
|
||||
</div>
|
||||
<div className='absolute left-0 top-0 flex size-full flex-col justify-between rounded-md bg-vignette p-2 text-white'>
|
||||
<Handlers show={show} onClick={onClick} />
|
||||
<div className='grid grid-cols-[1fr_auto] gap-2 opacity-75'>
|
||||
<span className='truncate'>{show.title}</span>
|
||||
{Boolean(show.release) && <span>{new Date(show.release).getFullYear()}</span>}
|
||||
</div>
|
||||
<div className='mb-[-5px] opacity-75'>
|
||||
<span className='z-[1] ml-auto mt-[-8px] flex w-full select-none items-center justify-between gap-1'>
|
||||
<Favorite show={show} />
|
||||
<Rating rating={show.rating} />
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Show;
|
||||
@@ -1,8 +1,8 @@
|
||||
import { FC } from 'react';
|
||||
|
||||
import Poster from '@/components/Poster';
|
||||
import { showPreviewModal } from '@/components/Preview';
|
||||
import ScrollNavigation from '@/components/ScrollNavigation';
|
||||
import Card from '@/components/Show';
|
||||
|
||||
interface Props {
|
||||
shows: Show[];
|
||||
@@ -17,7 +17,7 @@ const Gallery: FC<Props> = ({ shows }) => (
|
||||
>
|
||||
{shows.map((show) => (
|
||||
<li key={show.id} className='snap-start'>
|
||||
<Card className='!h-[350px] !w-[230px] text-sm' show={show} onClick={() => showPreviewModal({ show })} />
|
||||
<Poster className='!h-[350px] !w-[230px] text-sm' show={show} onClick={() => showPreviewModal({ show })} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
export const tabs = [
|
||||
{
|
||||
title: 'Trending',
|
||||
type: 'trending'
|
||||
},
|
||||
{
|
||||
title: 'Streaming',
|
||||
type: 'streaming'
|
||||
},
|
||||
{
|
||||
title: 'Trending',
|
||||
type: 'trending'
|
||||
},
|
||||
{
|
||||
title: 'In theaters',
|
||||
type: 'theater'
|
||||
|
||||
@@ -11,8 +11,8 @@ import useTrending from './useTrending';
|
||||
const Trending: FC = () => {
|
||||
const [active, setActive] = useState(tabs[0]);
|
||||
|
||||
const { data: trending, isFetched } = useTrending({ type: 'trending' });
|
||||
const { data: streaming } = useTrending({ type: 'streaming' });
|
||||
const { data: streaming, isFetched } = useTrending({ type: 'streaming' });
|
||||
const { data: trending } = useTrending({ type: 'trending' });
|
||||
const { data: theater } = useTrending({ type: 'theater' });
|
||||
|
||||
const shows = { trending, streaming, theater }[active.type] || [];
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
|
||||
import List from '@/components/List';
|
||||
import useMounted from '@/hooks/useMounted';
|
||||
import useUsersShows from '@/hooks/useUsersShows';
|
||||
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '../ui/tabs';
|
||||
|
||||
interface Props {
|
||||
list: 'favorite' | 'watchlist';
|
||||
label: string;
|
||||
}
|
||||
|
||||
const UsersList: FC<Props> = ({ list, label }) => {
|
||||
const isMounted = useMounted();
|
||||
|
||||
const movies = useUsersShows({ list, showType: 'movie' });
|
||||
const series = useUsersShows({ list, showType: 'tv' });
|
||||
|
||||
const tabs = [
|
||||
{ query: movies, title: 'Movies', key: 'movie' as const },
|
||||
{ query: series, title: 'Series', key: 'tv' as const }
|
||||
];
|
||||
|
||||
if (!isMounted) return null;
|
||||
|
||||
return (
|
||||
<Tabs defaultValue='movie' className='flex w-full flex-col items-center'>
|
||||
<TabsList className='grid w-[300px] grid-cols-2'>
|
||||
{tabs.map(({ title, key }) => (
|
||||
<TabsTrigger key={key} value={key}>
|
||||
{title}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
{tabs.map(({ query, key, title }) => (
|
||||
<TabsContent key={key} value={key} className='w-full'>
|
||||
{query.isFetched && !query.shows.length ? (
|
||||
<div className='flex h-40 w-full items-center justify-center text-center text-xl text-muted-foreground'>
|
||||
There are no {title.toLowerCase()} in your {label} list
|
||||
</div>
|
||||
) : (
|
||||
<List shows={query.shows} fetchNextPage={query.fetchNextPage} />
|
||||
)}
|
||||
</TabsContent>
|
||||
))}
|
||||
</Tabs>
|
||||
);
|
||||
};
|
||||
|
||||
export default UsersList;
|
||||
Reference in new issue
Block a user