From 899364ac85d1a3ca6378931d69c4b445fa2ebc09 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Tue, 31 Dec 2024 13:54:16 +0100 Subject: [PATCH] Use proper name for reader url chapter "index" param It's not the index of the chapter but the source order, which is starting at 1 and not 0 --- src/modules/core/AppRoute.constants.ts | 6 +++--- src/modules/reader/screens/Reader.tsx | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/modules/core/AppRoute.constants.ts b/src/modules/core/AppRoute.constants.ts index 9560023e..6a1d868e 100644 --- a/src/modules/core/AppRoute.constants.ts +++ b/src/modules/core/AppRoute.constants.ts @@ -150,8 +150,8 @@ export const AppRoutes = { path: '/tracker/login/oauth', }, reader: { - match: '/manga/:mangaId/chapter/:chapterIndex/*', - path: (mangaId: MangaIdInfo['id'], chapterIndex: ChapterSourceOrderInfo['sourceOrder']) => - `/manga/${mangaId}/chapter/${chapterIndex}`, + match: '/manga/:mangaId/chapter/:chapterSourceOrder/*', + path: (mangaId: MangaIdInfo['id'], chapterSourceOrder: ChapterSourceOrderInfo['sourceOrder']) => + `/manga/${mangaId}/chapter/${chapterSourceOrder}`, }, } satisfies TAppRoutes; diff --git a/src/modules/reader/screens/Reader.tsx b/src/modules/reader/screens/Reader.tsx index 248d7071..63d820fd 100644 --- a/src/modules/reader/screens/Reader.tsx +++ b/src/modules/reader/screens/Reader.tsx @@ -129,11 +129,11 @@ const BaseReader = ({ const [areSettingsSet, setAreSettingsSet] = useState(false); - const { chapterIndex: paramChapterIndex, mangaId: paramMangaId } = useParams<{ - chapterIndex: string; + const { chapterSourceOrder: paramChapterSourceOrder, mangaId: paramMangaId } = useParams<{ + chapterSourceOrder: string; mangaId: string; }>(); - const chapterIndex = Number(paramChapterIndex); + const chapterSourceOrder = Number(paramChapterSourceOrder); const mangaId = Number(paramMangaId); const mangaResponse = requestManager.useGetManga(GET_MANGA_READER, mangaId); @@ -162,8 +162,8 @@ const BaseReader = ({ const doesChapterExist = !chaptersResponse.loading && !chaptersResponse.error && - chapterIndex >= 0 && - chapterIndex <= chapters.length - 1; + chapterSourceOrder >= 0 && + chapterSourceOrder <= chapters.length - 1; const isLoading = !areSettingsSet || @@ -176,12 +176,12 @@ const BaseReader = ({ useLayoutEffect(() => { if (!manga || !currentChapter) { - setTitle(t('reader.title', { mangaId, chapterIndex })); + setTitle(t('reader.title', { mangaId, chapterIndex: chapterSourceOrder })); return; } setTitle(`${manga.title}: ${currentChapter.name}`); - }, [t, mangaId, chapterIndex, manga, currentChapter]); + }, [t, mangaId, chapterSourceOrder, manga, currentChapter]); useEffect(() => { doFetchPages(); @@ -333,7 +333,7 @@ const BaseReader = ({ useEffect(() => { const newMangaChapters = chaptersResponse.data?.chapters.nodes; const newCurrentChapter = newMangaChapters - ? (newMangaChapters[newMangaChapters.length - chapterIndex] ?? null) + ? (newMangaChapters[newMangaChapters.length - chapterSourceOrder] ?? null) : undefined; const newInitialChapter = initialChapter ?? newCurrentChapter; @@ -362,7 +362,7 @@ const BaseReader = ({ skipDupeChapter: newInitialChapter, }), }); - }, [chaptersResponse.data?.chapters.nodes, chapterIndex, shouldSkipDupChapters]); + }, [chaptersResponse.data?.chapters.nodes, chapterSourceOrder, shouldSkipDupChapters]); useLayoutEffect(() => { setOverride({