Display toast on metadata update not on lock update

This commit is contained in:
aditya.chandel
2025-01-25 22:57:56 -07:00
parent 596207b0c5
commit 5b214bee2d
2 changed files with 34 additions and 26 deletions
@@ -1,4 +1,4 @@
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave('saveButton')" *ngIf="bookMetadata$ | async as metadata" class="pt-2 flex flex-col h-full">
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" *ngIf="bookMetadata$ | async as metadata" class="pt-2 flex flex-col h-full">
<div class="overflow-y-scroll flex-1">
@@ -123,7 +123,38 @@ export class MetadataEditorComponent implements OnInit {
});
}
onSave(source: string): void {
onSave(): void {
this.metadataService.updateBookMetadata(this.currentBookId, this.buildMetadata()).subscribe({
next: (response) => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
this.metadataCenterService.emit(response);
},
error: () => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
}
});
}
toggleLock(field: string): void {
const isLocked = this.bookMetadataForm.get(field + 'Locked')?.value;
const updatedLockedState = !isLocked;
this.bookMetadataForm.get(field + 'Locked')?.setValue(updatedLockedState);
if (updatedLockedState) {
this.bookMetadataForm.get(field)?.disable();
} else {
this.bookMetadataForm.get(field)?.enable();
}
this.metadataService.updateBookMetadata(this.currentBookId, this.buildMetadata()).subscribe({
next: (response) => {
this.metadataCenterService.emit(response);
},
error: () => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update lock'});
}
});
}
private buildMetadata() {
const updatedBookMetadata: BookMetadata = {
bookId: this.currentBookId,
title: this.bookMetadataForm.get('title')?.value,
@@ -154,30 +185,7 @@ export class MetadataEditorComponent implements OnInit {
ratingLocked: this.bookMetadataForm.get('ratingLocked')?.value,
reviewCountLocked: this.bookMetadataForm.get('reviewCountLocked')?.value,
};
this.metadataService.updateBookMetadata(this.currentBookId, updatedBookMetadata).subscribe({
next: (response) => {
if (source === 'saveButton') {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
}
this.metadataCenterService.emit(response);
},
error: () => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
}
});
}
toggleLock(field: string): void {
const isLocked = this.bookMetadataForm.get(field + 'Locked')?.value;
const updatedLockedState = !isLocked;
this.bookMetadataForm.get(field + 'Locked')?.setValue(updatedLockedState);
if (updatedLockedState) {
this.bookMetadataForm.get(field)?.disable();
} else {
this.bookMetadataForm.get(field)?.enable();
}
this.onSave('lock');
return updatedBookMetadata;
}
closeDialog() {