feat: show page

This commit is contained in:
ner committed 2024-11-06 22:12:19 +02:00
1 parent abe1c795a1
commit 183c7231a1
26 files changed
+210 -176

No files matched your search

+24 -20
View File
@@ -1,36 +1,37 @@
'use client';
import { Bookmark, Copy, Heart, Play, Star } from 'lucide-react';
import { useRouter } from 'next/navigation';
import { Bookmark, Heart, Link, Play, Star } from 'lucide-react';
import { Button } from '@/components/ui/button';
import ButtonsGroup from '@/components/ui/buttons-group';
import useShowState, { useMutateShowState } from '@/hooks/useShowState';
import { useToast } from '@/hooks/useToast';
import { cn } from '@/lib/utils';
interface Props {
show: Show & Partial<Details>;
className: string;
onClose?: () => void;
}
const Actions = ({ onClose, show, className }: Props) => {
const router = useRouter();
const Actions = ({ show, className }: Props) => {
const { toast } = useToast();
const state = useShowState({ showId: show.id, showType: show.type });
const toggle = useMutateShowState(show);
return (
<div className={cn('flex gap-2 flex-wrap md:flex-grow-0 flex-grow', className)}>
<div className={cn('flex gap-2 flex-grow-0', className)}>
<ButtonsGroup className='pointer-events-none'>
<Button aria-label='Show rating' variant='outline'>
<Star size={14} />
</Button>
<Button variant='outline'>{show.rating.toFixed(1)}</Button>
<Button variant='outline' className='w-[43px]'>
{show.rating.toFixed(1)}
</Button>
</ButtonsGroup>
<ButtonsGroup>
<Button
aria-label='Toggle favorite'
title='Toggle favorite'
variant='outline'
disabled={toggle.list === 'favorite' && toggle.isPending}
onClick={() => toggle.mutate({ list: 'favorite', value: !state?.favorite })}
@@ -39,6 +40,7 @@ const Actions = ({ onClose, show, className }: Props) => {
</Button>
<Button
aria-label='Toggle watch list'
title='Toggle watch list'
variant='outline'
disabled={toggle.list === 'watchlist' && toggle.isPending}
onClick={() => toggle.mutate({ list: 'watchlist', value: !state?.watchlist })}
@@ -46,18 +48,20 @@ const Actions = ({ onClose, show, className }: Props) => {
<Bookmark size={14} className={cn({ 'fill-secondary-foreground': state?.watchlist })} />
</Button>
</ButtonsGroup>
<ButtonsGroup>
<Button
onClick={() => {
onClose?.();
router.push(`/similar?id=${show.id}&title=${encodeURIComponent(show.title)}&type=${show.type}`);
}}
aria-label='Similar show'
variant='outline'
>
<Copy size={14} />
Similar
</Button>
<Button
aria-label='Copy link'
title='Copy link'
variant='outline'
className='h-8 px-3'
onClick={() =>
navigator.clipboard
.writeText(`${location.origin}/${show.type}/${show.id}`)
.then(() => toast({ description: 'Link has been copied' }))
}
>
<Link size={14} />
</Button>
<ButtonsGroup className='ml-auto sm:ml-0'>
<Button
aria-label='Watch'
className='bg-red-600 transition-all duration-200 hover:bg-red-600 hover:shadow-lg hover:shadow-red-600/60 dark:bg-red-700'
+10 -7
View File
@@ -12,18 +12,21 @@ import { cn } from '@/lib/utils';
import Actions from './components/Actions';
interface Props {
show?: Show;
show?: Show & Partial<Details>;
showType?: Show['type'];
showId?: Show['id'];
className?: string;
posterClassName?: string;
onClose?: () => void;
poster?: ReactNode;
}
const Preview: FC<Props> = ({ show: baseShow, className, onClose, poster }) => {
const { data: detailedShow } = useDetails({ showId: baseShow?.id, showType: baseShow?.type });
const Preview: FC<Props> = ({ show: baseShow, showType, showId, className, posterClassName, onClose, poster }) => {
const { data: detailedShow } = useDetails({ showId: showId || baseShow?.id, showType: showType || baseShow?.type });
if (!baseShow) return null;
if (!baseShow && !detailedShow) return null;
const show: (Show & Partial<Details>) | undefined = detailedShow || baseShow;
const show: Show & Partial<Details> = (detailedShow || baseShow)!;
const isModal = Boolean(onClose);
@@ -35,7 +38,7 @@ const Preview: FC<Props> = ({ show: baseShow, className, onClose, poster }) => {
className
)}
>
{poster || <Poster className='mx-auto md:rounded-none md:rounded-l-xl' show={show} />}
{poster || <Poster className={cn('mx-auto md:rounded-none md:rounded-l-xl', posterClassName)} show={show} />}
<div className={cn('flex grow flex-col bg-background', { 'p-0 pt-1 md:p-2': isModal })}>
<span className='order-3 mb-4 text-3xl md:order-1 md:line-clamp-2'>{show.title}</span>
@@ -54,7 +57,7 @@ const Preview: FC<Props> = ({ show: baseShow, className, onClose, poster }) => {
)}
</div>
<Actions className='order-1 mb-4 mt-1 md:order-2 md:mt-0' show={show} onClose={onClose} />
<Actions className='order-1 mb-4 mt-1 md:order-2 md:mt-0' show={show} />
<p key={show.id} className='order-4 md:order-4 md:line-clamp-3' title={show.overview}>
{show.overview}