refactoring: improved types

This commit is contained in:
ner committed 2024-10-10 17:10:37 +03:00
1 parent 272178d668
commit 5c42608e99
10 files changed
+93 -88

No files matched your search

+2 -3
View File
@@ -7,7 +7,7 @@ import ToggleTrailer from '@/components/Show/components/Trailer';
import { Button } from '@/components/ui/button';
interface Props {
show: Show;
show: Show & Partial<Details>;
onClose?: () => void;
}
@@ -24,8 +24,7 @@ const Actions = ({ onClose, show }: Props) => (
className='h-8 w-1/2 grow'
onClick={() =>
showTorrentsModal({
showId: show.id,
showType: show.type,
imdbID: show.imdb_id!,
title: show.title,
backdrop: show.backdrop,
year: new Date(show.release).getFullYear()
+7 -2
View File
@@ -3,6 +3,7 @@
import { FC, ReactNode } from 'react';
import { create, InstanceProps } from 'react-modal-promise';
import useDetails from '@/components/Preview/useDetails';
import Card from '@/components/Show';
import Credits from '@/components/Show/components/Credits';
import { Modal } from '@/components/ui/dialog';
@@ -19,8 +20,12 @@ interface Props {
card?: ReactNode;
}
const Preview: FC<Props> = ({ show, className, onClose, children, card }) => {
if (!show) return null;
const Preview: FC<Props> = ({ show: baseShow, className, onClose, children, card }) => {
const { data: detailedShow } = useDetails({ showId: baseShow?.id, showType: baseShow?.type });
if (!baseShow) return null;
const show: Show & Partial<Details> | undefined = detailedShow || baseShow;
return (
<div className={cn('flex flex-col md:flex-row gap-2 rounded-xl', { 'p-2': Boolean(onClose) }, className)}>
+12
View File
@@ -0,0 +1,12 @@
import { useQuery } from '@tanstack/react-query';
import { details } from '@/api';
const useDetails = ({ showId, showType = 'movie' }: { showId?: Show['id']; showType?: Show['type'] }) =>
useQuery({
enabled: Boolean(showId && showType),
queryKey: ['details', showId, showType],
queryFn: () => details({ showId: showId!, showType })
});
export default useDetails;
@@ -16,14 +16,13 @@ import showHostManagerModal from './HostManager';
import useTorrents from './useTorrents';
interface Props extends InstanceProps<void> {
showId: Show['id'];
showType: Show['type'];
imdbID: string;
title: string;
year: number;
backdrop: string;
}
const showTorrentsModal = create(({ title, year, showType, showId, backdrop, onResolve }: Props) => {
const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }: Props) => {
const isMobile = matchMedia('(max-width: 600px)').matches;
const prefix = usePrefix();
const [sort, setSort] = useState<Sort>(Sort.seeds);
@@ -39,8 +38,7 @@ const showTorrentsModal = create(({ title, year, showType, showId, backdrop, onR
} = useTorrents({
query,
sort,
showId,
showType,
imdbID,
key,
queryFn
});
@@ -5,22 +5,20 @@ import { Sort } from '@/api/parsers';
const useTorrents = ({
query,
sort,
showId,
showType,
imdbID,
key,
queryFn
}: {
showId: Show['id'];
showType: Show['type'];
key: string;
query: string;
sort: Sort;
queryFn: (params: { query: string; sort: Sort; showId: Show['id']; showType: Show['type'] }) => Promise<Torrent[]>;
imdbID: string;
queryFn: (params: { query: string; sort: Sort; imdbID: string; }) => Promise<Torrent[]>;
}) => {
return useQuery({
enabled: Boolean(query),
queryKey: [key, query, sort, showId, showType],
queryFn: () => queryFn({ query, sort, showId, showType })
queryKey: [key, query, sort, imdbID],
queryFn: () => queryFn({ query, sort, imdbID })
});
};