From bb192ee21f298dc20c332851e0b940f1796c5e80 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sat, 11 Nov 2023 16:44:53 +0100 Subject: [PATCH] Fix incorrect last source status Co-authored-by: William Oldham --- src/hooks/useProviderScrape.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/hooks/useProviderScrape.tsx b/src/hooks/useProviderScrape.tsx index b7282175..8eeceff6 100644 --- a/src/hooks/useProviderScrape.tsx +++ b/src/hooks/useProviderScrape.tsx @@ -26,6 +26,8 @@ export function useScrape() { const startScraping = useCallback( async (media: ScrapeMedia) => { if (!providers) return null; + + let lastId: string | null = null; const output = await providers.runAll({ media, events: { @@ -56,6 +58,7 @@ export function useScrape() { return { ...s }; }); setCurrentSource(id); + lastId = id; }, update(evt) { setSources((s) => { @@ -94,6 +97,14 @@ export function useScrape() { }, }); + if (output && lastId) { + setSources((s) => { + if (!lastId) return s; + if (s[lastId]) s[lastId].status = "success"; + return { ...s }; + }); + } + return output; }, [setSourceOrder, setSources]