Skip to content

Commit

Permalink
fix(usediscover hook): fixing duplicate moves
Browse files Browse the repository at this point in the history
fixing duplicate movies that can be returned from the tmdb api
  • Loading branch information
gageorsburn committed Apr 27, 2024
1 parent 2101d0f commit 20b3eb6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/hooks/useDiscover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface BaseSearchResult<T> {
}

interface BaseMedia {
id: number;
mediaType: string;
mediaInfo?: {
status: MediaStatus;
Expand Down Expand Up @@ -82,6 +83,8 @@ const useDiscover = <
}
);

const resultIds: Set<number> = new Set<number>();

const isLoadingInitialData = !data && !error;
const isLoadingMore =
isLoadingInitialData ||
Expand All @@ -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(
Expand Down

0 comments on commit 20b3eb6

Please sign in to comment.