Add “Unassigned” shelf view for books not in any shelf
This commit is contained in:
committed by
Aditya Chandel
parent
22f10d0475
commit
4cb82d2ba7
@@ -38,6 +38,7 @@ export const routes: Routes = [
|
||||
{path: 'settings', component: SettingsComponent, canActivate: [AuthGuard]},
|
||||
{path: 'library/:libraryId/books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
||||
{path: 'shelf/:shelfId/books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
||||
{path: 'unshelved-books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
||||
{path: 'book/:bookId', component: BookMetadataCenterComponent, canActivate: [AuthGuard]}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,20 +57,32 @@ export class AppMenuComponent implements OnInit {
|
||||
);
|
||||
|
||||
this.shelfMenu$ = this.shelfService.shelfState$.pipe(
|
||||
map((state) => [
|
||||
{
|
||||
label: 'Shelves',
|
||||
separator: false,
|
||||
items: state.shelves?.map((shelf) => ({
|
||||
menu: this.libraryShelfMenuService.initializeShelfMenuItems(shelf),
|
||||
label: shelf.name,
|
||||
type: 'Shelf',
|
||||
icon: 'pi pi-' + shelf.icon,
|
||||
routerLink: [`/shelf/${shelf.id}/books`],
|
||||
bookCount$: this.shelfService.getBookCount(shelf.id ?? 0),
|
||||
})) || [],
|
||||
},
|
||||
])
|
||||
map((state) => {
|
||||
const shelves = state.shelves?.map((shelf) => ({
|
||||
menu: this.libraryShelfMenuService.initializeShelfMenuItems(shelf),
|
||||
label: shelf.name,
|
||||
type: 'Shelf',
|
||||
icon: 'pi pi-' + shelf.icon,
|
||||
routerLink: [`/shelf/${shelf.id}/books`],
|
||||
bookCount$: this.shelfService.getBookCount(shelf.id ?? 0),
|
||||
})) || [];
|
||||
|
||||
const unshelvedItem = {
|
||||
label: 'Unshelved',
|
||||
type: 'Shelf',
|
||||
icon: 'pi pi-inbox',
|
||||
routerLink: ['/unshelved-books'],
|
||||
bookCount$: this.shelfService.getUnshelvedBookCount?.() ?? of(0),
|
||||
};
|
||||
|
||||
return [
|
||||
{
|
||||
label: 'Shelves',
|
||||
separator: false,
|
||||
items: [unshelvedItem, ...shelves],
|
||||
},
|
||||
];
|
||||
})
|
||||
);
|
||||
|
||||
this.homeMenu$ = this.bookService.bookState$.pipe(
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<span *ngIf="(item.routerLink && !item.items) && item.visible !== false">
|
||||
<ng-container *ngIf="item.type === 'Library' || item.type === 'Shelf'">
|
||||
<p-button
|
||||
*ngIf="item.type !== 'Library' || canManipulateLibrary"
|
||||
*ngIf="(item.type !== 'Library' || canManipulateLibrary) && item.label !== 'Unshelved'"
|
||||
(click)="entitymenu.toggle($event)"
|
||||
(mouseover)="hovered = true"
|
||||
(mouseleave)="hovered = false"
|
||||
@@ -46,12 +46,12 @@
|
||||
<p-menu #entitymenu [model]="item.menu" [popup]="true" appendTo="body"></p-menu>
|
||||
</ng-container>
|
||||
|
||||
<ng-container *ngIf="item.type === 'Library' && !canManipulateLibrary || item.type === 'All Books'">
|
||||
<ng-container *ngIf="item.type === 'Library' && !canManipulateLibrary || item.type === 'All Books' || item.label === 'Unshelved'">
|
||||
<p class="text-[var(--primary-color)] pr-1">
|
||||
{{ (item.bookCount$ | async)?.toString() || '0' }}
|
||||
</p>
|
||||
</ng-container>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<ul *ngIf="item.items && item.visible !== false" [@children]="submenuAnimation">
|
||||
|
||||
Reference in New Issue
Block a user