feat: favorite & watch lists

This commit is contained in:
ner committed 2024-10-19 16:09:15 +03:00
1 parent 960a7a6242
commit 8858e47d38
51 files changed
+561 -290

No files matched your search

@@ -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;
@@ -0,0 +1,39 @@
'use client';
import { ReactNode } from 'react';
import { create, InstanceProps } from 'react-modal-promise';
import { Modal } from '@/components/ui/dialog';
import useTrailer from './useTrailer';
interface Props {
showId: Show['id'];
showType?: Show['type'];
children: ({ onPlay, disabled }: { onPlay: () => void; disabled: boolean }) => ReactNode;
}
const showTrailerModal = create(({ trailerKey, onResolve }: { trailerKey?: string } & InstanceProps<void>) => {
if (!trailerKey) return;
return (
<Modal className='block max-w-[930px] border-none bg-black p-0' style={{ aspectRatio: '16/9' }} onClose={onResolve}>
<iframe
allowFullScreen
allow='autoplay'
className='rounded-lg border-none'
width='100%'
height='100%'
src={`//www.youtube.com/embed/${trailerKey}?autoplay=1`}
/>
</Modal>
);
});
const ToggleTrailer = ({ showId, showType = 'movie', children }: Props) => {
const { data: trailer, isFetched } = useTrailer({ showId, showType });
return children({ onPlay: () => showTrailerModal({ trailerKey: trailer?.key }), disabled: isFetched && !trailer });
};
export default ToggleTrailer;
@@ -0,0 +1,21 @@
import { useQuery } from '@tanstack/react-query';
import { trailers } from '@/api';
interface Props {
showId: Show['id'];
showType: Show['type'];
}
const useTrailer = ({ showId, showType = 'movie' }: Props) =>
useQuery({
enabled: Boolean(showId),
queryKey: ['trailers', showId, showType],
queryFn: () => trailers({ showId, showType }),
select(trailers) {
const trailer = trailers[0];
return trailer?.site === 'YouTube' ? trailer : null;
}
});
export default useTrailer;
+42
View File
@@ -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;