Enhance book card component

This commit is contained in:
aditya.chandel
2024-12-25 13:39:00 -07:00
parent ebcd6cd908
commit cd2207f01e
9 changed files with 106 additions and 109 deletions
@@ -13,15 +13,18 @@
<div *ngIf="isAnyBookSelected()">
<div class="button-container">
<p-button *ngIf="(entityType$ | async) === 'Library'" icon="pi pi-ellipsis-v" label="Options" severity="primary" [rounded]="true" [outlined]="true" (click)="menu.toggle($event)"></p-button>
<p-button *ngIf="(entityType$ | async) === 'Shelf'" icon="pi pi-minus-circle" label="Unshelf" severity="primary" [rounded]="true" [outlined]="true" (click)="unshelfBooks()"></p-button>
<p-button icon="pi pi-times" label="Deselect" severity="warning" [rounded]="true" [outlined]="true" (click)="deselectAllBooks()"></p-button>
<p-button *ngIf="(entityType$ | async) === 'Library'" icon="pi pi-ellipsis-v" label="Options" severity="primary"
[rounded]="true" [outlined]="true" (click)="menu.toggle($event)"></p-button>
<p-button *ngIf="(entityType$ | async) === 'Shelf'" icon="pi pi-minus-circle" label="Unshelf" severity="primary"
[rounded]="true" [outlined]="true" (click)="unshelfBooks()"></p-button>
<p-button icon="pi pi-times" label="Deselect" severity="warning" [rounded]="true" [outlined]="true"
(click)="deselectAllBooks()"></p-button>
</div>
<p-menu #menu [model]="items" [popup]="true" appendTo="body"></p-menu>
</div>
<div class="library-header-right">
<p-dropdown optionLabel="name" placeholder="Select Sorting" />
<p-dropdown optionLabel="name" placeholder="Select Sorting"/>
<div class="zoom-controls">
<p-button icon="pi pi-minus" [rounded]="true" [outlined]="true" severity="info"></p-button>
<p-button icon="pi pi-plus" [rounded]="true" [outlined]="true" severity="info"></p-button>
@@ -36,7 +39,9 @@
<div class="virtual-scroller-item" *ngFor="let book of scroll.viewPortItems">
<app-book-card
[book]="book"
[onBookSelect]="handleBookSelect.bind(this)">
[isCheckboxEnabled]="true"
[onBookSelect]="handleBookSelect.bind(this)"
[isSelected]="selectedBooks.has(book.id)">
</app-book-card>
</div>
</div>
@@ -4,7 +4,7 @@ import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
import {LibraryService} from '../../service/library.service';
import {BookService} from '../../service/book.service';
import {map, switchMap} from 'rxjs/operators';
import {Observable, of} from 'rxjs';
import {Observable, of, Subject} from 'rxjs';
import {Book} from '../../model/book.model';
import {Library} from '../../model/library.model';
import {Shelf} from '../../model/book.model';
@@ -24,8 +24,9 @@ export class BooksBrowserComponent implements OnInit {
entityType$: Observable<string | null> | undefined;
items: MenuItem[] | undefined;
selectedBooks: Set<number> = new Set();
book: Book | undefined;
entity: Library | Shelf | null = null;
private deselectAllSubject = new Subject<void>(); // Subject to notify deselection
deselectAll$ = this.deselectAllSubject.asObservable();
constructor(
private activatedRoute: ActivatedRoute,
@@ -96,14 +97,12 @@ export class BooksBrowserComponent implements OnInit {
}
handleBookSelect(book: Book, selected: boolean): void {
handleBookSelect(bookId: number, selected: boolean): void {
if (selected) {
this.selectedBooks.add(book.id);
this.book = book; // Set the selected book
this.selectedBooks.add(bookId);
this.setupMenu();
} else {
this.selectedBooks.delete(book.id);
this.book = undefined; // Clear the selected book
this.selectedBooks.delete(bookId);
}
}
@@ -124,9 +123,6 @@ export class BooksBrowserComponent implements OnInit {
deselectAllBooks(): void {
this.selectedBooks.clear();
this.books$?.subscribe(books => {
books.forEach(book => book.selected = false);
});
}
isAnyBookSelected(): boolean {
@@ -143,7 +139,6 @@ export class BooksBrowserComponent implements OnInit {
baseZIndex: 10,
data: {
isMultiBooks: true,
book: this.book,
bookIds: this.selectedBooks
},
});
@@ -151,7 +146,7 @@ export class BooksBrowserComponent implements OnInit {
unshelfBooks() {
if (this.entity) {
this.bookService.assignShelvesToBook(this.selectedBooks, new Set(), new Set([this.entity.id])).subscribe(
this.bookService.updateBookShelves(this.selectedBooks, new Set(), new Set([this.entity.id])).subscribe(
() => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book\'s shelves updated'});
this.selectedBooks = new Set<number>();