Keep initial opened chapter as duplicate reference
In case "skip duplicated chapters" is enabled and the next chapter is from a different scanlator, the initial opened chapter should still be used to remove duplicated chapters. Otherwise, the original scanlator would get lost and the scanlator of the next chapter would get used, which was only a fallback chapter, because the initial chapters scanlator did not have a next chapter.
This commit is contained in:
@@ -342,7 +342,7 @@ export class Chapters {
|
|||||||
{
|
{
|
||||||
offset = ChapterOffset.NEXT,
|
offset = ChapterOffset.NEXT,
|
||||||
...options
|
...options
|
||||||
}: { offset?: ChapterOffset; onlyUnread?: boolean; skipDupe?: boolean } = {},
|
}: { offset?: ChapterOffset; onlyUnread?: boolean; skipDupe?: boolean; skipDupeChapter?: Chapter } = {},
|
||||||
): Chapter | undefined {
|
): Chapter | undefined {
|
||||||
const nextChapters = Chapters.getNextChapters(currentChapter, chapters, { offset, ...options });
|
const nextChapters = Chapters.getNextChapters(currentChapter, chapters, { offset, ...options });
|
||||||
|
|
||||||
@@ -360,7 +360,8 @@ export class Chapters {
|
|||||||
offset = ChapterOffset.NEXT,
|
offset = ChapterOffset.NEXT,
|
||||||
onlyUnread = false,
|
onlyUnread = false,
|
||||||
skipDupe = false,
|
skipDupe = false,
|
||||||
}: { offset?: ChapterOffset; onlyUnread?: boolean; skipDupe?: boolean } = {},
|
skipDupeChapter = fromChapter,
|
||||||
|
}: { offset?: ChapterOffset; onlyUnread?: boolean; skipDupe?: boolean; skipDupeChapter?: Chapter } = {},
|
||||||
): Chapter[] {
|
): Chapter[] {
|
||||||
const fromChapterIndex = chapters.findIndex((chapter) => chapter.id === fromChapter.id);
|
const fromChapterIndex = chapters.findIndex((chapter) => chapter.id === fromChapter.id);
|
||||||
|
|
||||||
@@ -370,7 +371,7 @@ export class Chapters {
|
|||||||
|
|
||||||
const nextChaptersIncludingCurrent = chapters.slice(sliceStartIndex, sliceEndIndex);
|
const nextChaptersIncludingCurrent = chapters.slice(sliceStartIndex, sliceEndIndex);
|
||||||
const uniqueNextChapters = skipDupe
|
const uniqueNextChapters = skipDupe
|
||||||
? Chapters.removeDuplicates(fromChapter, nextChaptersIncludingCurrent)
|
? Chapters.removeDuplicates(skipDupeChapter, nextChaptersIncludingCurrent)
|
||||||
: nextChaptersIncludingCurrent;
|
: nextChaptersIncludingCurrent;
|
||||||
const nextChapters = uniqueNextChapters.toSpliced(isNextChapterOffset ? -1 : 0, 1);
|
const nextChapters = uniqueNextChapters.toSpliced(isNextChapterOffset ? -1 : 0, 1);
|
||||||
|
|
||||||
|
|||||||
@@ -60,12 +60,13 @@ const getReaderComponent = (readerType: ReaderType) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const range = (n: number) => Array.from({ length: n }, (value, key) => key);
|
const range = (n: number) => Array.from({ length: n }, (value, key) => key);
|
||||||
const initialChapter = {
|
const fallbackChapter = {
|
||||||
pageCount: -1,
|
pageCount: -1,
|
||||||
sourceOrder: -1,
|
sourceOrder: -1,
|
||||||
chapterCount: 0,
|
chapterCount: 0,
|
||||||
lastPageRead: 0,
|
lastPageRead: 0,
|
||||||
name: 'Loading...',
|
name: 'Loading...',
|
||||||
|
manga: { id: -1 },
|
||||||
} as unknown as TChapter;
|
} as unknown as TChapter;
|
||||||
|
|
||||||
export function Reader() {
|
export function Reader() {
|
||||||
@@ -75,7 +76,7 @@ export function Reader() {
|
|||||||
|
|
||||||
const { chapterIndex, mangaId } = useParams<{ chapterIndex: string; mangaId: string }>();
|
const { chapterIndex, mangaId } = useParams<{ chapterIndex: string; mangaId: string }>();
|
||||||
|
|
||||||
const initialManga = useMemo(
|
const fallbackManga = useMemo(
|
||||||
() =>
|
() =>
|
||||||
({
|
({
|
||||||
id: +mangaId,
|
id: +mangaId,
|
||||||
@@ -101,7 +102,7 @@ export function Reader() {
|
|||||||
Number(mangaId) === loadedChapter.current?.manga.id &&
|
Number(mangaId) === loadedChapter.current?.manga.id &&
|
||||||
Number(chapterIndex) === loadedChapter.current?.sourceOrder &&
|
Number(chapterIndex) === loadedChapter.current?.sourceOrder &&
|
||||||
loadedChapter.current?.pageCount !== -1;
|
loadedChapter.current?.pageCount !== -1;
|
||||||
const manga = data?.manga ?? initialManga;
|
const manga = data?.manga ?? fallbackManga;
|
||||||
const {
|
const {
|
||||||
data: chapterData,
|
data: chapterData,
|
||||||
loading: isChapterLoading,
|
loading: isChapterLoading,
|
||||||
@@ -135,7 +136,16 @@ export function Reader() {
|
|||||||
};
|
};
|
||||||
loadedChapter.current = getLoadedChapter();
|
loadedChapter.current = getLoadedChapter();
|
||||||
|
|
||||||
const chapter = loadedChapter.current ?? initialChapter;
|
const chapter = loadedChapter.current ?? fallbackChapter;
|
||||||
|
|
||||||
|
const initialChapterRef = useRef<TChapter>(fallbackChapter);
|
||||||
|
if (initialChapterRef.current === fallbackChapter) {
|
||||||
|
initialChapterRef.current = chapter;
|
||||||
|
}
|
||||||
|
if (chapter.manga.id !== initialChapterRef.current?.manga.id) {
|
||||||
|
initialChapterRef.current = fallbackChapter;
|
||||||
|
}
|
||||||
|
|
||||||
const [fetchPages, { loading: arePagesLoading, error: pagesError }] = requestManager.useGetChapterPagesFetch(
|
const [fetchPages, { loading: arePagesLoading, error: pagesError }] = requestManager.useGetChapterPagesFetch(
|
||||||
chapter.id,
|
chapter.id,
|
||||||
);
|
);
|
||||||
@@ -187,39 +197,48 @@ export function Reader() {
|
|||||||
|
|
||||||
const uniqueChapters = useMemo(
|
const uniqueChapters = useMemo(
|
||||||
() =>
|
() =>
|
||||||
settings.skipDupChapters ? Chapters.removeDuplicates(chapter, mangaChapters ?? []) : mangaChapters ?? [],
|
settings.skipDupChapters
|
||||||
[chapter, mangaChapters, settings.skipDupChapters],
|
? Chapters.removeDuplicates(initialChapterRef.current, mangaChapters ?? [])
|
||||||
|
: mangaChapters ?? [],
|
||||||
|
[initialChapterRef.current, mangaChapters, settings.skipDupChapters],
|
||||||
);
|
);
|
||||||
const prevChapters = useMemo(
|
const prevChapters = useMemo(
|
||||||
() =>
|
() =>
|
||||||
Chapters.getNextChapters(chapter, mangaChapters ?? [], {
|
Chapters.getNextChapters(chapter, mangaChapters ?? [], {
|
||||||
offset: ChapterOffset.PREV,
|
offset: ChapterOffset.PREV,
|
||||||
skipDupe: settings.skipDupChapters,
|
skipDupe: settings.skipDupChapters,
|
||||||
|
skipDupeChapter: initialChapterRef.current,
|
||||||
}),
|
}),
|
||||||
[chapter, mangaChapters, settings.skipDupChapters],
|
[chapter, initialChapterRef.current, mangaChapters, settings.skipDupChapters],
|
||||||
);
|
);
|
||||||
const nextChapters = useMemo(
|
const nextChapters = useMemo(
|
||||||
() => Chapters.getNextChapters(chapter, mangaChapters ?? [], { skipDupe: settings.skipDupChapters }),
|
() =>
|
||||||
[chapter, mangaChapters, settings.skipDupChapters],
|
Chapters.getNextChapters(chapter, mangaChapters ?? [], {
|
||||||
|
skipDupe: settings.skipDupChapters,
|
||||||
|
skipDupeChapter: initialChapterRef.current,
|
||||||
|
}),
|
||||||
|
[chapter, initialChapterRef.current, mangaChapters, settings.skipDupChapters],
|
||||||
);
|
);
|
||||||
const prevChapter = useMemo(
|
const prevChapter = useMemo(
|
||||||
() =>
|
() =>
|
||||||
Chapters.getNextChapter(chapter, mangaChapters ?? [], {
|
Chapters.getNextChapter(chapter, mangaChapters ?? [], {
|
||||||
offset: ChapterOffset.PREV,
|
offset: ChapterOffset.PREV,
|
||||||
skipDupe: settings.skipDupChapters,
|
skipDupe: settings.skipDupChapters,
|
||||||
|
skipDupeChapter: initialChapterRef.current,
|
||||||
}),
|
}),
|
||||||
[chapter, mangaChapters, settings.skipDupChapters],
|
[chapter, initialChapterRef.current, mangaChapters, settings.skipDupChapters],
|
||||||
);
|
);
|
||||||
const nextChapter = useMemo(
|
const nextChapter = useMemo(
|
||||||
() =>
|
() =>
|
||||||
Chapters.getNextChapter(chapter, mangaChapters ?? [], {
|
Chapters.getNextChapter(chapter, mangaChapters ?? [], {
|
||||||
skipDupe: settings.skipDupChapters,
|
skipDupe: settings.skipDupChapters,
|
||||||
|
skipDupeChapter: initialChapterRef.current,
|
||||||
}),
|
}),
|
||||||
[chapter, mangaChapters, settings.skipDupChapters],
|
[chapter, initialChapterRef.current, mangaChapters, settings.skipDupChapters],
|
||||||
);
|
);
|
||||||
|
|
||||||
const updateChapter = (patch: UpdateChapterPatchInput) => {
|
const updateChapter = (patch: UpdateChapterPatchInput) => {
|
||||||
if (chapter === initialChapter) {
|
if (chapter === fallbackChapter) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,7 +423,7 @@ export function Reader() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chapter === initialChapter) {
|
if (chapter === fallbackChapter) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user