From 48b6906f41d39bcbd02844198244dcff1de37a3f Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Mon, 30 Dec 2024 11:41:09 -0700 Subject: [PATCH] Fix sorting. Todo: Refactor BookBrowserComponent, it's piece of crap --- .../book-browser/book-browser.component.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/booklore-ui/src/app/book/component/book-browser/book-browser.component.ts b/booklore-ui/src/app/book/component/book-browser/book-browser.component.ts index ec1de9782..1e75e0222 100644 --- a/booklore-ui/src/app/book/component/book-browser/book-browser.component.ts +++ b/booklore-ui/src/app/book/component/book-browser/book-browser.component.ts @@ -62,6 +62,7 @@ export class BookBrowserComponent implements OnInit { return fullPath === 'all-books' ? 'all-books' : null; }) ); + this.entityType = 'all-books'; this.bookState$ = this.fetchAllBooks(); } else { @@ -241,10 +242,14 @@ export class BookBrowserComponent implements OnInit { updateSortOption(sortOption: SortOption): void { this.selectedSort = sortOption; - const routeParam$ = this.getRouteParams(); - this.bookState$ = routeParam$.pipe( - switchMap(({libraryId, shelfId}) => this.fetchBooksByEntity(libraryId, shelfId)) - ); + if (this.entityType === 'all-books') { + this.bookState$ = this.fetchAllBooks(); + } else { + const routeParam$ = this.getRouteParams(); + this.bookState$ = routeParam$.pipe( + switchMap(({libraryId, shelfId}) => this.fetchBooksByEntity(libraryId, shelfId)) + ); + } if (this.entityType === 'Library') { this.libraryService.updateSort(this.entity?.id!, sortOption).subscribe(); } else if (this.entityType === 'Shelf') {