Fix Dashboard
This commit is contained in:
+1
-3
@@ -11,9 +11,7 @@
|
|||||||
[infiniteScrollDistance]="2"
|
[infiniteScrollDistance]="2"
|
||||||
[infiniteScrollThrottle]="50"
|
[infiniteScrollThrottle]="50"
|
||||||
#scrollContainer
|
#scrollContainer
|
||||||
[horizontal]="true"
|
[horizontal]="true">
|
||||||
(scrolled)="loadMore()"
|
|
||||||
(scroll)="onScroll($event)">
|
|
||||||
<div class="book-item" *ngFor="let book of booksSignal()">
|
<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"/>
|
<img [src]="coverImageSrc(book.id)" class="book-cover" alt="Cover of {{ book.metadata.title }}" loading="lazy"/>
|
||||||
<div class="book-info">
|
<div class="book-info">
|
||||||
|
|||||||
+4
-21
@@ -23,8 +23,6 @@ export class DashboardScrollerComponent implements OnInit {
|
|||||||
@Input() title: string = 'Last Read Books';
|
@Input() title: string = 'Last Read Books';
|
||||||
@ViewChild('scrollContainer') scrollContainer!: ElementRef;
|
@ViewChild('scrollContainer') scrollContainer!: ElementRef;
|
||||||
|
|
||||||
private currentPage: number = 0;
|
|
||||||
|
|
||||||
booksSignal = computed(() => {
|
booksSignal = computed(() => {
|
||||||
return this.bookListType === 'lastRead' ? this.bookService.lastReadBooks() : this.bookService.latestAddedBooks();
|
return this.bookListType === 'lastRead' ? this.bookService.lastReadBooks() : this.bookService.latestAddedBooks();
|
||||||
});
|
});
|
||||||
@@ -37,12 +35,11 @@ export class DashboardScrollerComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadBooks(): void {
|
loadBooks(): void {
|
||||||
if (this.bookListType === 'lastRead') {
|
if (this.bookListType === 'lastRead' && !this.bookService.lastReadBooksLoaded) {
|
||||||
this.bookService.getLastReadBooks(this.currentPage);
|
this.bookService.getLastReadBooks();
|
||||||
} else {
|
} else if (this.bookListType === 'latestAdded' && !this.bookService.latestAddedBooksLoaded) {
|
||||||
this.bookService.getLatestAddedBooks(this.currentPage);
|
this.bookService.getLatestAddedBooks();
|
||||||
}
|
}
|
||||||
this.currentPage++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
coverImageSrc(bookId: number): string {
|
coverImageSrc(bookId: number): string {
|
||||||
@@ -58,20 +55,6 @@ export class DashboardScrollerComponent implements OnInit {
|
|||||||
window.open(url, '_blank');
|
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) {
|
openBookInfo(bookId: number, libraryId: number) {
|
||||||
this.router.navigate(['/library', libraryId, 'book', bookId, 'info']);
|
this.router.navigate(['/library', libraryId, 'book', bookId, 'info']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,6 @@ export class LibraryBrowserComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadBooks(): void {
|
loadBooks(): void {
|
||||||
console.log('loadBooks()')
|
|
||||||
this.bookService.loadBooks(this.libraryIdSignal(), this.currentPage).subscribe({
|
this.bookService.loadBooks(this.libraryIdSignal(), this.currentPage).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
this.books = [...this.books, ...response.content];
|
this.books = [...this.books, ...response.content];
|
||||||
|
|||||||
@@ -15,21 +15,11 @@ export class BookService {
|
|||||||
|
|
||||||
#lastReadBooks = signal<Book[]>([]);
|
#lastReadBooks = signal<Book[]>([]);
|
||||||
lastReadBooks = computed(this.#lastReadBooks);
|
lastReadBooks = computed(this.#lastReadBooks);
|
||||||
|
lastReadBooksLoaded: boolean = false;
|
||||||
|
|
||||||
#latestAddedBooks = signal<Book[]>([]);
|
#latestAddedBooks = signal<Book[]>([]);
|
||||||
latestAddedBooks = computed(this.#latestAddedBooks);
|
latestAddedBooks = computed(this.#latestAddedBooks);
|
||||||
|
latestAddedBooksLoaded: boolean = false;
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
constructor(private http: HttpClient) {
|
constructor(private http: HttpClient) {
|
||||||
@@ -49,8 +39,8 @@ export class BookService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLastReadBooks(page: number) {
|
getLastReadBooks() {
|
||||||
this.http.get<PaginatedBooksResponse>(`${this.bookUrl}?page=${page}&size=25&sortBy=lastReadTime&sortDir=desc`).pipe(
|
this.http.get<PaginatedBooksResponse>(`${this.bookUrl}?page=0&size=25&sortBy=lastReadTime&sortDir=desc`).pipe(
|
||||||
map(response => response.content),
|
map(response => response.content),
|
||||||
catchError(error => {
|
catchError(error => {
|
||||||
console.error('Error loading last read books:', error);
|
console.error('Error loading last read books:', error);
|
||||||
@@ -59,13 +49,14 @@ export class BookService {
|
|||||||
).subscribe(
|
).subscribe(
|
||||||
(books) => {
|
(books) => {
|
||||||
this.#lastReadBooks.set([...this.#lastReadBooks(), ...books]);
|
this.#lastReadBooks.set([...this.#lastReadBooks(), ...books]);
|
||||||
|
this.lastReadBooksLoaded = true;
|
||||||
console.log("Loaded last read books")
|
console.log("Loaded last read books")
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLatestAddedBooks(page: number) {
|
getLatestAddedBooks() {
|
||||||
this.http.get<PaginatedBooksResponse>(`${this.bookUrl}?page=${page}&size=25&sortBy=addedOn&sortDir=desc`).pipe(
|
this.http.get<PaginatedBooksResponse>(`${this.bookUrl}?page=0&size=25&sortBy=addedOn&sortDir=desc`).pipe(
|
||||||
map(response => response.content),
|
map(response => response.content),
|
||||||
catchError(error => {
|
catchError(error => {
|
||||||
console.error('Error loading latest added books:', error);
|
console.error('Error loading latest added books:', error);
|
||||||
@@ -74,6 +65,7 @@ export class BookService {
|
|||||||
).subscribe(
|
).subscribe(
|
||||||
(books) => {
|
(books) => {
|
||||||
this.#latestAddedBooks.set([...this.#latestAddedBooks(), ...books]);
|
this.#latestAddedBooks.set([...this.#latestAddedBooks(), ...books]);
|
||||||
|
this.latestAddedBooksLoaded = true;
|
||||||
console.log("Loaded latest added books")
|
console.log("Loaded latest added books")
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -81,7 +73,7 @@ export class BookService {
|
|||||||
|
|
||||||
searchBooks(query: string): Observable<Book[]> {
|
searchBooks(query: string): Observable<Book[]> {
|
||||||
if (query.length < 2) {
|
if (query.length < 2) {
|
||||||
return new Observable<Book[]>();
|
return of([]);
|
||||||
}
|
}
|
||||||
return this.http.get<Book[]>(`${this.bookUrl}/search?title=${encodeURIComponent(query)}`);
|
return this.http.get<Book[]>(`${this.bookUrl}/search?title=${encodeURIComponent(query)}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user