add confirm modal when removing an entry from collection

This commit is contained in:
X4Lo committed 2024-05-11 05:08:59 +01:00
1 parent c51a389519
commit e991329e71
1 file changed
+31 -13
@@ -5,6 +5,7 @@ import { Entry } from '../../../../shared/models/entry.model';
import { trigger, transition, style, animate } from '@angular/animations'; import { trigger, transition, style, animate } from '@angular/animations';
import { UserCollectionService } from '../../../../core/services/userCollection.service'; import { UserCollectionService } from '../../../../core/services/userCollection.service';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ConfirmModalComponent } from '../../../../shared/components/modals/confirm-modal/confirm-modal.component';
@Component({ @Component({
selector: 'app-userCollection-grid-card', selector: 'app-userCollection-grid-card',
@@ -80,19 +81,36 @@ export class UserCollectionGridCardComponent {
} }
removeEntryFromList() { removeEntryFromList() {
// TODO: add confirm modal const dialogRef = this.dialog.open(ConfirmModalComponent, {
this.userCollectionService width: '400px',
.removeEntryFromCollection(this.listId, this.entry.id) data: {
.subscribe({ title: 'Confirmation',
next: (response) => { message: `Are you sure you want to remove ${this.entry.title} from this collection?`,
console.log('Entry successfully removed from list.', response); type: 'danger',
this.entry.id = 0; },
this.entry.isInLibrary = false; });
},
error: (error) => { dialogRef.afterClosed().subscribe((result) => {
console.error('Error removing entry from list:', error); if (result) {
}, if (result.confirmed != true) return;
});
this.userCollectionService
.removeEntryFromCollection(this.listId, this.entry.id)
.subscribe({
next: (response) => {
// TODO confirm notification
console.log('Entry successfully removed from list.', response);
this.entry.id = 0;
this.entry.isInLibrary = false;
},
error: (error) => {
// TODO error notification
console.error('Error removing entry from list:', error);
},
});
}
});
} }
// ? EVENTS // ? EVENTS