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;