From 856e928c4466dc056c4d03fe051f9b6d25750fce Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Tue, 11 Feb 2025 02:09:28 +0100 Subject: [PATCH] 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 --- src/modules/reader/hooks/useReaderSetChaptersState.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/modules/reader/hooks/useReaderSetChaptersState.ts b/src/modules/reader/hooks/useReaderSetChaptersState.ts index abdcdcb5..34ba5ff6 100644 --- a/src/modules/reader/hooks/useReaderSetChaptersState.ts +++ b/src/modules/reader/hooks/useReaderSetChaptersState.ts @@ -7,6 +7,7 @@ */ import { useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; import { Chapters } from '@/modules/chapter/services/Chapters.ts'; import { DirectionOffset } from '@/Base.types.ts'; import { requestManager } from '@/lib/requests/RequestManager.ts'; @@ -22,6 +23,8 @@ export const useReaderSetChaptersState = ( setReaderStateChapters: ReaderStateChapters['setReaderStateChapters'], shouldSkipDupChapters: IReaderSettings['shouldSkipDupChapters'], ) => { + const navigate = useNavigate(); + useEffect(() => { const newMangaChapters = chaptersResponse.data?.chapters.nodes; const newCurrentChapter = newMangaChapters @@ -60,6 +63,10 @@ export const useReaderSetChaptersState = ( const hasInitialChapterChanged = newInitialChapter != null && newInitialChapter.id !== initialChapter?.id; + if (hasInitialChapterChanged) { + navigate('', { replace: true }); + } + setReaderStateChapters((prevState) => { const hasCurrentChapterChanged = newCurrentChapter?.id !== prevState.currentChapter?.id; return {