fix: response type

This commit is contained in:
ner committed 2024-10-25 22:04:06 +03:00
1 parent 345cf911a4
commit 5e9e7cb6a8
4 files changed
+4 -64

No files matched your search

@@ -1,39 +0,0 @@
'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;
@@ -1,21 +0,0 @@
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;