Fix Dashboard
This commit is contained in:
+1
-3
@@ -11,9 +11,7 @@
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
#scrollContainer
|
||||
[horizontal]="true"
|
||||
(scrolled)="loadMore()"
|
||||
(scroll)="onScroll($event)">
|
||||
[horizontal]="true">
|
||||
<div class="book-item" *ngFor="let book of booksSignal()">
|
||||
<img [src]="coverImageSrc(book.id)" class="book-cover" alt="Cover of {{ book.metadata.title }}" loading="lazy"/>
|
||||
<div class="book-info">
|
||||
|
||||
+4
-21
@@ -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']);
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -15,21 +15,11 @@ export class BookService {
|
||||
|
||||
#lastReadBooks = signal<Book[]>([]);
|
||||
lastReadBooks = computed(this.#lastReadBooks);
|
||||
lastReadBooksLoaded: boolean = false;
|
||||
|
||||
#latestAddedBooks = signal<Book[]>([]);
|
||||
latestAddedBooks = computed(this.#latestAddedBooks);
|
||||
|
||||
getBooksByLibraryId(libraryId: number, page: number) {
|
||||
this.http.get<PaginatedBooksResponse>(`${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<PaginatedBooksResponse>(`${this.bookUrl}?page=${page}&size=25&sortBy=lastReadTime&sortDir=desc`).pipe(
|
||||
getLastReadBooks() {
|
||||
this.http.get<PaginatedBooksResponse>(`${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<PaginatedBooksResponse>(`${this.bookUrl}?page=${page}&size=25&sortBy=addedOn&sortDir=desc`).pipe(
|
||||
getLatestAddedBooks() {
|
||||
this.http.get<PaginatedBooksResponse>(`${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<Book[]> {
|
||||
if (query.length < 2) {
|
||||
return new Observable<Book[]>();
|
||||
return of([]);
|
||||
}
|
||||
return this.http.get<Book[]>(`${this.bookUrl}/search?title=${encodeURIComponent(query)}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user