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 { UserCollectionService } from '../../../../core/services/userCollection.service';
import { Router } from '@angular/router';
import { ConfirmModalComponent } from '../../../../shared/components/modals/confirm-modal/confirm-modal.component';
@Component({
selector: 'app-userCollection-grid-card',
@@ -80,19 +81,36 @@ export class UserCollectionGridCardComponent {
}
removeEntryFromList() {
// TODO: add confirm modal
this.userCollectionService
.removeEntryFromCollection(this.listId, this.entry.id)
.subscribe({
next: (response) => {
console.log('Entry successfully removed from list.', response);
this.entry.id = 0;
this.entry.isInLibrary = false;
},
error: (error) => {
console.error('Error removing entry from list:', error);
},
});
const dialogRef = this.dialog.open(ConfirmModalComponent, {
width: '400px',
data: {
title: 'Confirmation',
message: `Are you sure you want to remove ${this.entry.title} from this collection?`,
type: 'danger',
},
});
dialogRef.afterClosed().subscribe((result) => {
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