diff --git a/components/Header/components/Search/useSearch.ts b/components/Header/components/Search/useSearch.ts index c80f106..844d409 100644 --- a/components/Header/components/Search/useSearch.ts +++ b/components/Header/components/Search/useSearch.ts @@ -4,7 +4,7 @@ import { search } from '@/api'; import useInfiniteList from '@/hooks/useInfiniteList'; const useSearch = ({ query, type }: { query: string; type: Show['type'] }) => { - const previous = useRef([]); + const previousRef = useRef([]); const infiniteQuery = useInfiniteList({ queryKey: ['search', query, type], @@ -13,16 +13,16 @@ const useSearch = ({ query, type }: { query: string; type: Show['type'] }) => { }); if (infiniteQuery.isFetched) { - previous.current = infiniteQuery.shows; + previousRef.current = infiniteQuery.shows; } if (!query) { - previous.current = []; + previousRef.current = []; } return { ...infiniteQuery, - shows: infiniteQuery.isLoading ? previous.current : infiniteQuery.shows + shows: infiniteQuery.isLoading ? previousRef.current : infiniteQuery.shows }; }; diff --git a/components/Show/components/Torrents/components/Player/index.tsx b/components/Show/components/Torrents/components/Player/index.tsx index 73ccdc4..d8a548f 100644 --- a/components/Show/components/Torrents/components/Player/index.tsx +++ b/components/Show/components/Torrents/components/Player/index.tsx @@ -39,7 +39,7 @@ const showPlayer = create(({ onResolve, magnet, backdrop, title }: Props) => { } return ( - +
setIsReady(true)} /> diff --git a/components/Show/components/Torrents/components/TorrentsTable/index.tsx b/components/Show/components/Torrents/components/TorrentsTable/index.tsx index 72e3d2f..c1f74ef 100644 --- a/components/Show/components/Torrents/components/TorrentsTable/index.tsx +++ b/components/Show/components/Torrents/components/TorrentsTable/index.tsx @@ -1,9 +1,8 @@ -import { FC, Fragment, useState } from 'react'; -import { Cast, Copy, ListVideo, Loader, Magnet, Play } from 'lucide-react'; +import { FC, Fragment } from 'react'; +import { Cast, Copy, ListVideo, Magnet, Play } from 'lucide-react'; import { Sort } from '@/api/parsers'; import { Quality } from '@/api/parsers/yts/models'; -import { Button } from '@/components/ui/button'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { useCastMagnet, usePrefix } from '@/hooks/useMagnetHosts'; @@ -16,27 +15,13 @@ interface Props { title: string; backdrop: string; torrents: Torrent[]; - year: number; - withYear?: boolean; sort: Sort; sortable: boolean; provider: string; onChangeSort: (sort: Sort) => void; - onToggleYear: () => void; } -const TorrentsTable: FC = ({ - title, - torrents, - backdrop, - year, - withYear, - sort, - sortable, - provider, - onChangeSort, - onToggleYear -}) => { +const TorrentsTable: FC = ({ title, torrents, backdrop, sort, sortable, provider, onChangeSort }) => { const prefix = usePrefix(); const cast = useCastMagnet(); @@ -45,16 +30,6 @@ const TorrentsTable: FC = ({ return ( - - -
- {title} - -
-
-
Title Resolution diff --git a/components/Show/components/Torrents/index.tsx b/components/Show/components/Torrents/index.tsx index 457b667..94797f7 100644 --- a/components/Show/components/Torrents/index.tsx +++ b/components/Show/components/Torrents/index.tsx @@ -4,6 +4,7 @@ import { TabsContent } from '@radix-ui/react-tabs'; import { Loader } from 'lucide-react'; import { Sort } from '@/api/parsers'; +import { Button } from '@/components/ui/button'; import { Modal } from '@/components/ui/dialog'; import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'; @@ -22,7 +23,8 @@ const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }: const [sort, setSort] = useState(Sort.seeds); const [withYear, setWithYear] = useState(true); const [providerKey, setProviderKey] = useState(providers.yts.key); - const nextProviderKey = useRef(null); + + const nextProviderKeyRef = useRef(null); const yts = useTorrents({ query: title, queryFn: providers.yts.queryFn, sort, key: providers.yts.key, imdbID }); const tpb = useTorrents({ @@ -44,19 +46,33 @@ const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }: } ]; - useEffect(() => { - if (!nextProviderKey.current || providerKey === nextProviderKey.current) return; + const checkIsEmpty = (query: (typeof tabs)[number]['query']) => + query.isFetched && !query.isLoading && !query.data?.length; - setProviderKey(nextProviderKey.current); - nextProviderKey.current = null; - }); + useEffect(() => { + if (!nextProviderKeyRef.current || providerKey === nextProviderKeyRef.current) return; + + setProviderKey(nextProviderKeyRef.current); + nextProviderKeyRef.current = null; + }, [providerKey, yts.isFetched, tpb.isFetched]); return ( - + +
+ {title} + +
- {tabs.map(({ provider }) => ( - setProviderKey(provider.key)}> + {tabs.map(({ provider, query }) => ( + setProviderKey(provider.key)} + > {provider.label} ))} @@ -64,10 +80,10 @@ const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }: {tabs.map(({ provider, query }, index) => { const nextIndex = index + 1; - const isEmpty = query.isFetched && !query.isLoading && !query.data?.length; + const isEmpty = checkIsEmpty(query); if (isEmpty && tabs[nextIndex]) { - nextProviderKey.current = tabs[nextIndex].provider.key; + nextProviderKeyRef.current = tabs[nextIndex].provider.key; } return ( @@ -80,9 +96,6 @@ const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }: onChangeSort={setSort} provider={provider.key} torrents={query.data || []} - year={year} - withYear={withYear} - onToggleYear={() => setWithYear((w) => !w)} /> {(query.isLoading || query.isFetching) && (