From 6688c813e665b90257d19ae8cda032ba3a318816 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Sun, 9 Mar 2025 17:29:16 +0800 Subject: [PATCH] fix: don't open book if failed to download book (#541) --- .../src/app/library/components/Bookshelf.tsx | 6 +++--- .../src/app/library/components/BookshelfItem.tsx | 9 ++++----- apps/readest-app/src/app/library/page.tsx | 10 ++++++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/apps/readest-app/src/app/library/components/Bookshelf.tsx b/apps/readest-app/src/app/library/components/Bookshelf.tsx index ce221844..6c548b4d 100644 --- a/apps/readest-app/src/app/library/components/Bookshelf.tsx +++ b/apps/readest-app/src/app/library/components/Bookshelf.tsx @@ -21,9 +21,9 @@ interface BookshelfProps { libraryBooks: Book[]; isSelectMode: boolean; handleImportBooks: () => void; - handleBookUpload: (book: Book) => void; - handleBookDownload: (book: Book) => void; - handleBookDelete: (book: Book) => void; + handleBookUpload: (book: Book) => Promise; + handleBookDownload: (book: Book) => Promise; + handleBookDelete: (book: Book) => Promise; handleSetSelectMode: (selectMode: boolean) => void; handleShowDetailsBook: (book: Book) => void; booksTransferProgress: { [key: string]: number | null }; diff --git a/apps/readest-app/src/app/library/components/BookshelfItem.tsx b/apps/readest-app/src/app/library/components/BookshelfItem.tsx index 297a2b43..b790b37e 100644 --- a/apps/readest-app/src/app/library/components/BookshelfItem.tsx +++ b/apps/readest-app/src/app/library/components/BookshelfItem.tsx @@ -72,9 +72,9 @@ interface BookshelfItemProps { transferProgress: number | null; setLoading: React.Dispatch>; toggleSelection: (hash: string) => void; - handleBookUpload: (book: Book) => void; - handleBookDownload: (book: Book) => void; - handleBookDelete: (book: Book) => void; + handleBookUpload: (book: Book) => Promise; + handleBookDownload: (book: Book) => Promise; + handleBookDelete: (book: Book) => Promise; handleSetSelectMode: (selectMode: boolean) => void; handleShowDetailsBook: (book: Book) => void; } @@ -109,9 +109,8 @@ const BookshelfItem: React.FC = ({ let available = false; const loadingTimeout = setTimeout(() => setLoading(true), 200); try { - await handleBookDownload(book); + available = await handleBookDownload(book); updateBook(envConfig, book); - available = true; } finally { if (loadingTimeout) clearTimeout(loadingTimeout); setLoading(false); diff --git a/apps/readest-app/src/app/library/page.tsx b/apps/readest-app/src/app/library/page.tsx index 5609cba5..b8d4825b 100644 --- a/apps/readest-app/src/app/library/page.tsx +++ b/apps/readest-app/src/app/library/page.tsx @@ -360,17 +360,18 @@ const LibraryPageContent = ({ searchParams }: { searchParams: ReadonlyURLSearchP title: book.title, }), }); + return true; } catch (err) { if (err instanceof Error) { if (err.message.includes('Not authenticated') && settings.keepLogin) { navigateToLogin(router); - return; + return false; } else if (err.message.includes('Insufficient storage quota')) { eventDispatcher.dispatch('toast', { type: 'error', message: _('Insufficient storage quota'), }); - return; + return false; } } eventDispatcher.dispatch('toast', { @@ -379,6 +380,7 @@ const LibraryPageContent = ({ searchParams }: { searchParams: ReadonlyURLSearchP title: book.title, }), }); + return false; } }; @@ -395,6 +397,7 @@ const LibraryPageContent = ({ searchParams }: { searchParams: ReadonlyURLSearchP title: book.title, }), }); + return true; } catch { eventDispatcher.dispatch('toast', { message: _('Failed to download book: {{title}}', { @@ -402,6 +405,7 @@ const LibraryPageContent = ({ searchParams }: { searchParams: ReadonlyURLSearchP }), type: 'error', }); + return false; } }; @@ -417,6 +421,7 @@ const LibraryPageContent = ({ searchParams }: { searchParams: ReadonlyURLSearchP title: book.title, }), }); + return true; } catch { eventDispatcher.dispatch('toast', { message: _('Failed to delete book: {{title}}', { @@ -424,6 +429,7 @@ const LibraryPageContent = ({ searchParams }: { searchParams: ReadonlyURLSearchP }), type: 'error', }); + return false; } };