Fix chapter preloading after chapter selection from list

When a chapter gets opened via the chapter list in the reader, the visible chapter state gets reset.
The problem was that after this happened, the passed location state did not get reset and the "visible chapter state" constantly got reset everytime the state of a chapter changed
This commit is contained in:
schroda
2025-02-11 02:09:28 +01:00
parent 7e5b3435a9
commit 856e928c44

View File

@@ -7,6 +7,7 @@
*/ */
import { useEffect } from 'react'; import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { Chapters } from '@/modules/chapter/services/Chapters.ts'; import { Chapters } from '@/modules/chapter/services/Chapters.ts';
import { DirectionOffset } from '@/Base.types.ts'; import { DirectionOffset } from '@/Base.types.ts';
import { requestManager } from '@/lib/requests/RequestManager.ts'; import { requestManager } from '@/lib/requests/RequestManager.ts';
@@ -22,6 +23,8 @@ export const useReaderSetChaptersState = (
setReaderStateChapters: ReaderStateChapters['setReaderStateChapters'], setReaderStateChapters: ReaderStateChapters['setReaderStateChapters'],
shouldSkipDupChapters: IReaderSettings['shouldSkipDupChapters'], shouldSkipDupChapters: IReaderSettings['shouldSkipDupChapters'],
) => { ) => {
const navigate = useNavigate();
useEffect(() => { useEffect(() => {
const newMangaChapters = chaptersResponse.data?.chapters.nodes; const newMangaChapters = chaptersResponse.data?.chapters.nodes;
const newCurrentChapter = newMangaChapters const newCurrentChapter = newMangaChapters
@@ -60,6 +63,10 @@ export const useReaderSetChaptersState = (
const hasInitialChapterChanged = newInitialChapter != null && newInitialChapter.id !== initialChapter?.id; const hasInitialChapterChanged = newInitialChapter != null && newInitialChapter.id !== initialChapter?.id;
if (hasInitialChapterChanged) {
navigate('', { replace: true });
}
setReaderStateChapters((prevState) => { setReaderStateChapters((prevState) => {
const hasCurrentChapterChanged = newCurrentChapter?.id !== prevState.currentChapter?.id; const hasCurrentChapterChanged = newCurrentChapter?.id !== prevState.currentChapter?.id;
return { return {