Add “Unassigned” shelf view for books not in any shelf

This commit is contained in:
adityachandelgit
2025-05-15 21:11:33 -06:00
committed by Aditya Chandel
parent 22f10d0475
commit 4cb82d2ba7
6 changed files with 74 additions and 30 deletions
@@ -3,14 +3,17 @@
<div class="flex justify-between items-center p-2 rounded-t-xl mb-4 bg-[var(--card-background)]">
<div class="flex items-center pl-2">
<ng-container *ngIf="entityType$ | async as entityType">
<p *ngIf="entityType !== EntityType.ALL_BOOKS" class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
<p *ngIf="entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED" class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
{{ entityType }}: {{ (entity$ | async)?.name }}
</p>
<p *ngIf="entityType === EntityType.ALL_BOOKS" class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
All Books
</p>
<p *ngIf="entityType === EntityType.UNSHELVED" class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
Unshelved Books
</p>
<div *ngIf="userService.userData$ | async as userData">
<div *ngIf="entityType !== EntityType.ALL_BOOKS && userData.permissions.canManipulateLibrary">
<div *ngIf="entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED && userData.permissions.canManipulateLibrary">
<p-button icon="pi pi-ellipsis-v" [rounded]="true" [text]="true" severity="info" (click)="entitymenu.toggle($event)"></p-button>
<p-menu #entitymenu [model]="entityOptions" [popup]="true" appendTo="body"></p-menu>
</div>
@@ -126,7 +129,7 @@
<div class="flex justify-between gap-8">
<ng-container *ngIf="entityType$ | async as entityType">
<p-button
*ngIf="entityType === EntityType.LIBRARY || entityType === EntityType.ALL_BOOKS"
*ngIf="entityType === EntityType.LIBRARY || entityType === EntityType.ALL_BOOKS || entityType === EntityType.UNSHELVED"
icon="pi pi-bookmark-fill"
outlined="true"
severity="info"
@@ -36,7 +36,8 @@ import {LockUnlockMetadataDialogComponent} from './lock-unlock-metadata-dialog/l
export enum EntityType {
LIBRARY = 'Library',
SHELF = 'Shelf',
ALL_BOOKS = 'All Books'
ALL_BOOKS = 'All Books',
UNSHELVED = 'Unshelved Books',
}
const QUERY_PARAMS = {
@@ -137,21 +138,21 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
ngOnInit(): void {
this.bookService.loadBooks();
const isAllBooksRoute = this.activatedRoute.snapshot.routeConfig?.path === 'all-books';
const currentPath = this.activatedRoute.snapshot.routeConfig?.path;
if (isAllBooksRoute) {
if (currentPath === 'all-books') {
this.entityType = EntityType.ALL_BOOKS;
this.entityType$ = of(EntityType.ALL_BOOKS);
this.entity$ = of(null);
this.bookState$ = this.fetchAllBooks();
} else if (currentPath === 'unshelved-books') {
this.entityType = EntityType.UNSHELVED;
this.entityType$ = of(EntityType.UNSHELVED);
this.entity$ = of(null);
} else {
const routeEntityInfo$ = this.getEntityInfoFromRoute();
this.bookState$ = routeEntityInfo$.pipe(
switchMap(({entityId, entityType}) => this.fetchBooksByEntity(entityId, entityType)),
);
this.entity$ = routeEntityInfo$.pipe(
switchMap(({entityId, entityType}) => this.fetchEntity(entityId, entityType))
);
@@ -255,6 +256,23 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
);
}
private fetchUnshelvedBooks(): Observable<BookState> {
return this.bookService.bookState$.pipe(
map(bookState => {
const unshelvedBooks = (bookState.books || []).filter(book =>
!book.shelves || book.shelves.length === 0
);
return {
...bookState,
books: unshelvedBooks
};
}),
map(bookState => this.processBookState(bookState)),
switchMap(bookState => this.headerFilter(bookState)),
switchMap(bookState => this.sideBarFilter(bookState))
);
}
private sideBarFilter(bookState: BookState): Observable<BookState> {
return this.selectedFilter.pipe(
map((activeFilters: Record<string, any[]> | null) => {
@@ -287,7 +305,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
});
});
return { ...bookState, books: filteredBooks };
return {...bookState, books: filteredBooks};
})
);
}
@@ -397,6 +415,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
applySortOption(sortOption: SortOption): void {
if (this.entityType === EntityType.ALL_BOOKS) {
this.bookState$ = this.fetchAllBooks();
} else if (this.entityType === EntityType.UNSHELVED) {
this.bookState$ = this.fetchUnshelvedBooks();
} else {
const routeParam$ = this.getEntityInfoFromRoute();
this.bookState$ = routeParam$.pipe(
@@ -106,4 +106,12 @@ export class ShelfService {
)
);
}
getUnshelvedBookCount(): Observable<number> {
return this.bookService.bookState$.pipe(
map(state =>
(state.books || []).filter(book => !book.shelves || book.shelves.length === 0).length
)
);
}
}