Skip to content

Commit

Permalink
Prevent duplicated mangas in source browse
Browse files Browse the repository at this point in the history
Regression introduced with 6186cb0
  • Loading branch information
schroda committed May 5, 2024
1 parent 6b955ef commit 3aa156b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/screens/SourceMangas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ const SOURCE_CONTENT_TYPE_TO_ERROR_MSG_KEY: { [contentType in SourceContentType]
};

const getUniqueMangas = (mangas: TPartialManga[]): TPartialManga[] => {
const mangaIdToManga: Record<TPartialManga['id'], TPartialManga> = {};
const uniqueMangas: TPartialManga[] = [];

mangas.forEach((manga) => {
const isDuplicate = uniqueMangas.some((uniqueManga) => uniqueManga.id === manga.id);
const isDuplicate = !!mangaIdToManga[manga.id];
if (!isDuplicate) {
mangaIdToManga[manga.id] = manga;
uniqueMangas.push(manga);
}
});
Expand Down Expand Up @@ -174,16 +176,12 @@ const useSourceManga = (

pages.forEach((page, index) => {
const pageItems = page.data?.fetchSourceManga.mangas ?? ([] as FetchItemsResult);
const uniqueItems = getUniqueMangas([...allItems, ...pageItems]);
const uniquePageItems = pageItems.filter(
(pageItem) => !!uniqueItems.find((uniqueItem) => uniqueItem.id === pageItem.id),
);
const nonLibraryItems = uniquePageItems.filter((item) => !hideLibraryEntries || !item.inLibrary);
// const nonLibraryItems = uniquePageItems;
const nonLibraryPageItems = pageItems.filter((item) => !hideLibraryEntries || !item.inLibrary);
const uniqueItems = getUniqueMangas([...allItems, ...nonLibraryPageItems]);

const isLastPage = !isPageLoading && pages.length === index + 1;
filteredOutAllItemsOfFetchedPage = isLastPage && !nonLibraryItems.length && !!pageItems.length;
allItems = [...allItems, ...nonLibraryItems];
filteredOutAllItemsOfFetchedPage = isLastPage && !nonLibraryPageItems.length && !!pageItems.length;
allItems = uniqueItems;
});

return allItems;
Expand Down

0 comments on commit 3aa156b

Please sign in to comment.