diff --git a/booklore-ui/src/app/book/service/book.service.ts b/booklore-ui/src/app/book/service/book.service.ts index 2667dc2f8..bda1c8669 100644 --- a/booklore-ui/src/app/book/service/book.service.ts +++ b/booklore-ui/src/app/book/service/book.service.ts @@ -98,17 +98,13 @@ export class BookService { return this.http.put(`${this.url}/${bookId}/book-viewer-setting`, bookSetting); } - updateLastReadTime(bookId: number): Observable { - const timestamp = Math.floor(Date.now() / 1000).toString(); - return this.http.put(`${this.url}/${bookId}/update-last-read/${timestamp}`, {}).pipe( - tap(() => { - const currentState = this.bookStateSubject.value; - const updatedBooks = (currentState.books || []).map(book => - book.id === bookId ? {...book, lastReadTime: timestamp} : book - ); - this.bookStateSubject.next({...currentState, books: updatedBooks}); - }) + updateLastReadTime(bookId: number) { + const timestamp = new Date().toISOString(); + const currentState = this.bookStateSubject.value; + const updatedBooks = (currentState.books || []).map(book => + book.id === bookId ? {...book, lastReadTime: timestamp} : book ); + this.bookStateSubject.next({...currentState, books: updatedBooks}); } readBook(bookId: number): void { @@ -118,14 +114,11 @@ export class BookService { if (book.bookType === "PDF") { const url = `/pdf-viewer/book/${book.id}`; window.open(url, '_blank'); - this.updateLastReadTime(book.id).subscribe({ - next: () => { - }, - error: err => console.error('Failed to update last read time', err), - }); + this.updateLastReadTime(book.id); } else if (book.bookType === "EPUB") { const url = `/epub-viewer/book/${book.id}`; window.open(url, '_blank'); + this.updateLastReadTime(book.id); } else { console.error('Unsupported book type:', book.bookType); } diff --git a/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.ts b/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.ts index d1d9ebe66..5c60f1e70 100644 --- a/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.ts +++ b/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.ts @@ -38,19 +38,26 @@ export class DashboardScrollerComponent implements OnInit { ...state, books: (state.books || []) .filter(book => book.lastReadTime) - .sort((a, b) => new Date(b.lastReadTime!).getTime() - new Date(a.lastReadTime!).getTime()) + .sort((a, b) => { + const aTime = new Date(a.lastReadTime!).getTime(); + const bTime = new Date(b.lastReadTime!).getTime(); + return bTime - aTime; + }) .slice(0, 25) })) ); } - if (this.bookListType === 'latestAdded') { this.bookState$ = this.bookService.bookState$.pipe( map((state: BookState) => ({ ...state, books: (state.books || []) .filter(book => book.addedOn) - .sort((a, b) => new Date(b.addedOn!).getTime() - new Date(a.addedOn!).getTime()) + .sort((a, b) => { + const aTime = new Date(a.addedOn!).getTime(); + const bTime = new Date(b.addedOn!).getTime(); + return bTime - aTime; + }) .slice(0, 25) })) );