From f887fff5384beac6b6557573d350b71c378d18a1 Mon Sep 17 00:00:00 2001 From: Gage Orsburn Date: Fri, 26 Apr 2024 23:55:25 -0400 Subject: [PATCH] fix(usediscover hook): filter out duplicate movies filter out any duplicate movies that tmdb can return from it's api --- src/hooks/useDiscover.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/hooks/useDiscover.ts b/src/hooks/useDiscover.ts index 2a2acd02f..8e53494f0 100644 --- a/src/hooks/useDiscover.ts +++ b/src/hooks/useDiscover.ts @@ -10,6 +10,7 @@ export interface BaseSearchResult { } interface BaseMedia { + id: number; mediaType: string; mediaInfo?: { status: MediaStatus; @@ -82,6 +83,8 @@ const useDiscover = < } ); + const resultIds: Set = new Set(); + const isLoadingInitialData = !data && !error; const isLoadingMore = isLoadingInitialData || @@ -94,7 +97,18 @@ const useDiscover = < setSize(size + 1); }; - let titles = (data ?? []).reduce((a, v) => [...a, ...v.results], [] as T[]); + let titles = (data ?? []).reduce((a, v) => { + const results: T[] = []; + + for (const result of v.results) { + if (!resultIds.has(result.id)) { + resultIds.add(result.id); + results.push(result); + } + } + + return [...a, ...results]; + }, [] as T[]); if (settings.currentSettings.hideAvailable && hideAvailable) { titles = titles.filter(