From 0a562d90ac01481025038f8306d5e8bf37d548ce Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Thu, 8 May 2025 15:26:58 +0800 Subject: [PATCH] fix: maintain library state across reader/library navigation, closes #1072 (#1096) --- apps/readest-app/src/app/library/page.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/readest-app/src/app/library/page.tsx b/apps/readest-app/src/app/library/page.tsx index 3968e77b..109c85cd 100644 --- a/apps/readest-app/src/app/library/page.tsx +++ b/apps/readest-app/src/app/library/page.tsx @@ -285,16 +285,17 @@ const LibraryPageContent = ({ searchParams }: { searchParams: ReadonlyURLSearchP const settings = await appService.loadSettings(); setSettings(settings); - const libraryBooks = await appService.loadLibraryBooks(); + // Reuse the library from the store when we return from the reader + const library = libraryBooks.length > 0 ? libraryBooks : await appService.loadLibraryBooks(); if (checkOpenWithBooks) { - await handleOpenWithBooks(appService, libraryBooks); + await handleOpenWithBooks(appService, library); } else { setCheckOpenWithBooks(false); - setLibrary(libraryBooks); + setLibrary(library); } if (checkLastOpenBooks && settings.openLastBooks) { - await handleOpenLastBooks(appService, settings.lastOpenBooks, libraryBooks); + await handleOpenLastBooks(appService, settings.lastOpenBooks, library); } else { setCheckLastOpenBooks(false); } @@ -304,14 +305,14 @@ const LibraryPageContent = ({ searchParams }: { searchParams: ReadonlyURLSearchP setLoading(false); }; - const handleOpenWithBooks = async (appService: AppService, libraryBooks: Book[]) => { + const handleOpenWithBooks = async (appService: AppService, library: Book[]) => { const openWithFiles = (await parseOpenWithFiles()) || []; if (openWithFiles.length > 0) { - await processOpenWithFiles(appService, openWithFiles, libraryBooks); + await processOpenWithFiles(appService, openWithFiles, library); } else { setCheckOpenWithBooks(false); - setLibrary(libraryBooks); + setLibrary(library); } };