diff --git a/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.ts b/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.ts
index 322efc95b..f9211944e 100644
--- a/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.ts
+++ b/booklore-ui/src/app/book/component/dashboard-scroller/dashboard-scroller.component.ts
@@ -23,8 +23,6 @@ export class DashboardScrollerComponent implements OnInit {
@Input() title: string = 'Last Read Books';
@ViewChild('scrollContainer') scrollContainer!: ElementRef;
- private currentPage: number = 0;
-
booksSignal = computed(() => {
return this.bookListType === 'lastRead' ? this.bookService.lastReadBooks() : this.bookService.latestAddedBooks();
});
@@ -37,12 +35,11 @@ export class DashboardScrollerComponent implements OnInit {
}
loadBooks(): void {
- if (this.bookListType === 'lastRead') {
- this.bookService.getLastReadBooks(this.currentPage);
- } else {
- this.bookService.getLatestAddedBooks(this.currentPage);
+ if (this.bookListType === 'lastRead' && !this.bookService.lastReadBooksLoaded) {
+ this.bookService.getLastReadBooks();
+ } else if (this.bookListType === 'latestAdded' && !this.bookService.latestAddedBooksLoaded) {
+ this.bookService.getLatestAddedBooks();
}
- this.currentPage++;
}
coverImageSrc(bookId: number): string {
@@ -58,20 +55,6 @@ export class DashboardScrollerComponent implements OnInit {
window.open(url, '_blank');
}
- loadMore() {
- /*this.loadBooks();
- this.currentPage++;*/
- }
-
- onScroll(event: any): void {
- /*const container = this.scrollContainer.nativeElement;
- const scrollRight = container.scrollWidth - container.scrollLeft === container.clientWidth;
- if (scrollRight) {
- this.currentPage++;
- this.loadBooks();
- }*/
- }
-
openBookInfo(bookId: number, libraryId: number) {
this.router.navigate(['/library', libraryId, 'book', bookId, 'info']);
}
diff --git a/booklore-ui/src/app/book/component/library-browser/library-browser.component.ts b/booklore-ui/src/app/book/component/library-browser/library-browser.component.ts
index f9744fcc0..b26489ef1 100644
--- a/booklore-ui/src/app/book/component/library-browser/library-browser.component.ts
+++ b/booklore-ui/src/app/book/component/library-browser/library-browser.component.ts
@@ -107,7 +107,6 @@ export class LibraryBrowserComponent implements OnInit, OnDestroy {
}
loadBooks(): void {
- console.log('loadBooks()')
this.bookService.loadBooks(this.libraryIdSignal(), this.currentPage).subscribe({
next: (response) => {
this.books = [...this.books, ...response.content];
diff --git a/booklore-ui/src/app/book/service/book.service.ts b/booklore-ui/src/app/book/service/book.service.ts
index 5b6b5f41b..e890d8912 100644
--- a/booklore-ui/src/app/book/service/book.service.ts
+++ b/booklore-ui/src/app/book/service/book.service.ts
@@ -15,21 +15,11 @@ export class BookService {
#lastReadBooks = signal
([]);
lastReadBooks = computed(this.#lastReadBooks);
+ lastReadBooksLoaded: boolean = false;
#latestAddedBooks = signal([]);
latestAddedBooks = computed(this.#latestAddedBooks);
-
- getBooksByLibraryId(libraryId: number, page: number) {
- this.http.get(`${this.libraryUrl}/${libraryId}/book?page=${page}&size=${this.pageSize}`)
- .pipe(
- map(response => {
- catchError(error => {
- console.error('Error loading libraries:', error);
- return of([]);
- })
- })
- ).subscribe()
- }
+ latestAddedBooksLoaded: boolean = false;
constructor(private http: HttpClient) {
@@ -49,8 +39,8 @@ export class BookService {
);
}
- getLastReadBooks(page: number) {
- this.http.get(`${this.bookUrl}?page=${page}&size=25&sortBy=lastReadTime&sortDir=desc`).pipe(
+ getLastReadBooks() {
+ this.http.get(`${this.bookUrl}?page=0&size=25&sortBy=lastReadTime&sortDir=desc`).pipe(
map(response => response.content),
catchError(error => {
console.error('Error loading last read books:', error);
@@ -59,13 +49,14 @@ export class BookService {
).subscribe(
(books) => {
this.#lastReadBooks.set([...this.#lastReadBooks(), ...books]);
+ this.lastReadBooksLoaded = true;
console.log("Loaded last read books")
}
);
}
- getLatestAddedBooks(page: number) {
- this.http.get(`${this.bookUrl}?page=${page}&size=25&sortBy=addedOn&sortDir=desc`).pipe(
+ getLatestAddedBooks() {
+ this.http.get(`${this.bookUrl}?page=0&size=25&sortBy=addedOn&sortDir=desc`).pipe(
map(response => response.content),
catchError(error => {
console.error('Error loading latest added books:', error);
@@ -74,6 +65,7 @@ export class BookService {
).subscribe(
(books) => {
this.#latestAddedBooks.set([...this.#latestAddedBooks(), ...books]);
+ this.latestAddedBooksLoaded = true;
console.log("Loaded latest added books")
}
);
@@ -81,7 +73,7 @@ export class BookService {
searchBooks(query: string): Observable {
if (query.length < 2) {
- return new Observable();
+ return of([]);
}
return this.http.get(`${this.bookUrl}/search?title=${encodeURIComponent(query)}`);
}