Prevent duplicated mangas in source browse

Regression introduced with 6186cb0ea3
This commit is contained in:
schroda
2024-05-05 23:27:52 +02:00
parent 6b955ef705
commit 3aa156b2c9

View File

@@ -95,11 +95,13 @@ const SOURCE_CONTENT_TYPE_TO_ERROR_MSG_KEY: { [contentType in SourceContentType]
}; };
const getUniqueMangas = (mangas: TPartialManga[]): TPartialManga[] => { const getUniqueMangas = (mangas: TPartialManga[]): TPartialManga[] => {
const mangaIdToManga: Record<TPartialManga['id'], TPartialManga> = {};
const uniqueMangas: TPartialManga[] = []; const uniqueMangas: TPartialManga[] = [];
mangas.forEach((manga) => { mangas.forEach((manga) => {
const isDuplicate = uniqueMangas.some((uniqueManga) => uniqueManga.id === manga.id); const isDuplicate = !!mangaIdToManga[manga.id];
if (!isDuplicate) { if (!isDuplicate) {
mangaIdToManga[manga.id] = manga;
uniqueMangas.push(manga); uniqueMangas.push(manga);
} }
}); });
@@ -174,16 +176,12 @@ const useSourceManga = (
pages.forEach((page, index) => { pages.forEach((page, index) => {
const pageItems = page.data?.fetchSourceManga.mangas ?? ([] as FetchItemsResult); const pageItems = page.data?.fetchSourceManga.mangas ?? ([] as FetchItemsResult);
const uniqueItems = getUniqueMangas([...allItems, ...pageItems]); const nonLibraryPageItems = pageItems.filter((item) => !hideLibraryEntries || !item.inLibrary);
const uniquePageItems = pageItems.filter( const uniqueItems = getUniqueMangas([...allItems, ...nonLibraryPageItems]);
(pageItem) => !!uniqueItems.find((uniqueItem) => uniqueItem.id === pageItem.id),
);
const nonLibraryItems = uniquePageItems.filter((item) => !hideLibraryEntries || !item.inLibrary);
// const nonLibraryItems = uniquePageItems;
const isLastPage = !isPageLoading && pages.length === index + 1; const isLastPage = !isPageLoading && pages.length === index + 1;
filteredOutAllItemsOfFetchedPage = isLastPage && !nonLibraryItems.length && !!pageItems.length; filteredOutAllItemsOfFetchedPage = isLastPage && !nonLibraryPageItems.length && !!pageItems.length;
allItems = [...allItems, ...nonLibraryItems]; allItems = uniqueItems;
}); });
return allItems; return allItems;