From 868eb70506e38125d5e6b4c26044667eb361a76a Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Fri, 28 Jan 2022 08:47:16 -0800 Subject: [PATCH] Bugfixes (#1004) * Refactored the code for choosing the tab to select when updates occur or first load. Specials will no longer be auto-selected if present. We will always try to select Storyline. * Fixed a bug where marking a chapter as unread was actually making it read * When loading a book, put a spinner in the action bar * Fixed an issue with last page not getting marked as read with epubs due to a bugfix from last release * Removed some debug code --- UI/Web/src/app/_services/action.service.ts | 2 +- .../book-reader/book-reader.component.html | 16 ++++- .../book-reader/book-reader.component.ts | 51 +++++++++----- .../series-detail.component.html | 8 +-- .../series-detail/series-detail.component.ts | 69 ++++++++++++------- 5 files changed, 96 insertions(+), 50 deletions(-) diff --git a/UI/Web/src/app/_services/action.service.ts b/UI/Web/src/app/_services/action.service.ts index 992265971..d03dbb552 100644 --- a/UI/Web/src/app/_services/action.service.ts +++ b/UI/Web/src/app/_services/action.service.ts @@ -214,7 +214,7 @@ export class ActionService implements OnDestroy { * @param callback Optional callback to perform actions after API completes */ markChapterAsUnread(seriesId: number, chapter: Chapter, callback?: ChapterActionCallback) { - this.readerService.saveProgress(seriesId, chapter.volumeId, chapter.id, chapter.pages).pipe(take(1)).subscribe(results => { + this.readerService.saveProgress(seriesId, chapter.volumeId, chapter.id, 0).pipe(take(1)).subscribe(results => { chapter.pagesRead = 0; this.toastr.success('Marked as unread'); if (callback) { diff --git a/UI/Web/src/app/book-reader/book-reader/book-reader.component.html b/UI/Web/src/app/book-reader/book-reader/book-reader.component.html index 05c76eabb..4ea4f1e4a 100644 --- a/UI/Web/src/app/book-reader/book-reader/book-reader.component.html +++ b/UI/Web/src/app/book-reader/book-reader/book-reader.component.html @@ -129,18 +129,28 @@ -
{{bookTitle}} (Incognito Mode)
+
+ +
+ Loading book... +
+
+ + {{bookTitle}} + (Incognito Mode) + +
diff --git a/UI/Web/src/app/book-reader/book-reader/book-reader.component.ts b/UI/Web/src/app/book-reader/book-reader/book-reader.component.ts index cfbb88f8e..d7bfba788 100644 --- a/UI/Web/src/app/book-reader/book-reader/book-reader.component.ts +++ b/UI/Web/src/app/book-reader/book-reader/book-reader.component.ts @@ -235,6 +235,13 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy { } } + get IsNextChapter(): boolean { + return this.pageNum + 1 >= this.maxPages; + } + get IsPrevChapter(): boolean { + return this.pageNum === 0; + } + get drawerBackgroundColor() { return this.darkMode ? '#010409': '#fff'; } @@ -344,12 +351,24 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy { this.lastSeenScrollPartPath = path; } - if (this.lastSeenScrollPartPath !== '' && !this.incognitoMode) { - this.readerService.saveProgress(this.seriesId, this.volumeId, this.chapterId, this.pageNum, this.lastSeenScrollPartPath).pipe(take(1)).subscribe(() => {/* No operation */}); + if (this.lastSeenScrollPartPath !== '') { + this.saveProgress(); } }); } + saveProgress() { + let tempPageNum = this.pageNum; + if (this.pageNum == this.maxPages - 1) { + tempPageNum = this.pageNum + 1; + } + + if (!this.incognitoMode) { + this.readerService.saveProgress(this.seriesId, this.volumeId, this.chapterId, tempPageNum, this.lastSeenScrollPartPath).pipe(take(1)).subscribe(() => {/* No operation */}); + } + + } + ngOnDestroy(): void { const bodyNode = this.document.querySelector('body'); if (bodyNode !== undefined && bodyNode !== null && this.originalBodyColor !== undefined) { @@ -450,9 +469,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy { if (this.pageNum >= this.maxPages) { this.pageNum = this.maxPages - 1; - if (!this.incognitoMode) { - this.readerService.saveProgress(this.seriesId, this.volumeId, this.chapterId, this.pageNum).pipe(take(1)).subscribe(() => {/* No operation */}); - } + this.saveProgress(); } this.readerService.getNextChapter(this.seriesId, this.volumeId, this.chapterId, this.readingListId).pipe(take(1)).subscribe(chapterId => { @@ -711,9 +728,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy { loadPage(part?: string | undefined, scrollTop?: number | undefined) { this.isLoading = true; - if (!this.incognitoMode) { - this.readerService.saveProgress(this.seriesId, this.volumeId, this.chapterId, this.pageNum).pipe(take(1)).subscribe(() => {/* No operation */}); - } + this.saveProgress(); this.bookService.getBookPage(this.chapterId, this.pageNum).pipe(take(1)).subscribe(content => { this.page = this.domSanitizer.bypassSecurityTrustHtml(content); @@ -764,8 +779,8 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy { setPageNum(pageNum: number) { if (pageNum < 0) { this.pageNum = 0; - } else if (pageNum >= this.maxPages) { - this.pageNum = this.maxPages - 1; + } else if (pageNum >= this.maxPages - 1) { // This case handles when we are using the pager to move to the next volume/chapter, the pageNum will get incremented past maxPages // NOTE: I made a change where I removed - 1 in comparison, it's breaking page progress + this.pageNum = this.maxPages; // } else { this.pageNum = pageNum; } @@ -794,6 +809,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy { prevPage() { const oldPageNum = this.pageNum; + if (this.readingDirection === ReadingDirection.LeftToRight) { this.setPageNum(this.pageNum - 1); } else { @@ -816,18 +832,21 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy { event.stopPropagation(); event.preventDefault(); } - const oldPageNum = this.pageNum; + if (oldPageNum + 1 === this.maxPages) { + // Move to next volume/chapter automatically + this.loadNextChapter(); + return; + } + + if (this.readingDirection === ReadingDirection.LeftToRight) { this.setPageNum(this.pageNum + 1); } else { this.setPageNum(this.pageNum - 1); } - if (oldPageNum + 1 === this.maxPages) { - // Move to next volume/chapter automatically - this.loadNextChapter(); - } + if (oldPageNum === this.pageNum) { return; } @@ -1051,7 +1070,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy { const newRoute = this.readerService.getNextChapterUrl(this.router.url, this.chapterId, this.incognitoMode, this.readingListMode, this.readingListId); window.history.replaceState({}, '', newRoute); this.toastr.info('Incognito mode is off. Progress will now start being tracked.'); - this.readerService.saveProgress(this.seriesId, this.volumeId, this.chapterId, this.pageNum).pipe(take(1)).subscribe(() => {/* No operation */}); + this.saveProgress(); } toggleFullscreen() { diff --git a/UI/Web/src/app/series-detail/series-detail.component.html b/UI/Web/src/app/series-detail/series-detail.component.html index 5dce1d30e..e124d7379 100644 --- a/UI/Web/src/app/series-detail/series-detail.component.html +++ b/UI/Web/src/app/series-detail/series-detail.component.html @@ -63,7 +63,7 @@