Properly handle not skipping duplicate chapters

The filtered chapter list of the reader state always incorrectly filtered out duplicated chapters even while the setting was disabled
This commit is contained in:
schroda
2025-02-05 20:05:36 +01:00
parent a32c88a549
commit 187693ce5a
2 changed files with 14 additions and 6 deletions

View File

@@ -191,7 +191,7 @@ const BaseReaderViewer = forwardRef(
const isLtrReadingDirection = readingDirection === ReadingDirection.LTR;
const initialChapterIndex = useMemo(
() => chapters.findIndex((chapter) => chapter.id === initialChapter?.id),
[initialChapter?.id],
[chapters, initialChapter?.id],
);
const chaptersToRender = useMemo(
() =>
@@ -199,7 +199,7 @@ const BaseReaderViewer = forwardRef(
Math.max(0, initialChapterIndex - visibleChapters.trailing),
Math.min(chapters.length, initialChapterIndex + visibleChapters.leading + 1),
),
[chapters, initialChapterIndex, visibleChapters.trailing, visibleChapters.leading, chapters.length],
[chapters, initialChapterIndex, visibleChapters.trailing, visibleChapters.leading],
);
const currentChapterIndex = useMemo(
() => chaptersToRender.findIndex((chapter) => chapter.id === currentChapter?.id),

View File

@@ -46,6 +46,17 @@ export const useReaderSetChaptersState = (
skipDupe: shouldSkipDupChapters,
skipDupeChapter: newChapterForDuplicatesHandling,
});
const newChapters = (() => {
if (!newMangaChapters || !newChapterForDuplicatesHandling) {
return [];
}
if (shouldSkipDupChapters) {
return Chapters.removeDuplicates(newChapterForDuplicatesHandling, newMangaChapters);
}
return newMangaChapters;
})();
const hasInitialChapterChanged = newInitialChapter != null && newInitialChapter.id !== initialChapter?.id;
@@ -54,10 +65,7 @@ export const useReaderSetChaptersState = (
return {
...prevState,
mangaChapters: newMangaChapters ?? [],
chapters:
newChapterForDuplicatesHandling && newMangaChapters
? Chapters.removeDuplicates(newChapterForDuplicatesHandling, newMangaChapters)
: [],
chapters: newChapters,
initialChapter: newInitialChapter,
chapterForDuplicatesHandling: newChapterForDuplicatesHandling,
currentChapter: newCurrentChapter,