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
+19 -1
@@ -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,20 +81,37 @@ export class UserCollectionGridCardComponent {
} }
removeEntryFromList() { removeEntryFromList() {
// TODO: add confirm modal 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 this.userCollectionService
.removeEntryFromCollection(this.listId, this.entry.id) .removeEntryFromCollection(this.listId, this.entry.id)
.subscribe({ .subscribe({
next: (response) => { next: (response) => {
// TODO confirm notification
console.log('Entry successfully removed from list.', response); console.log('Entry successfully removed from list.', response);
this.entry.id = 0; this.entry.id = 0;
this.entry.isInLibrary = false; this.entry.isInLibrary = false;
}, },
error: (error) => { error: (error) => {
// TODO error notification
console.error('Error removing entry from list:', error); console.error('Error removing entry from list:', error);
}, },
}); });
} }
});
}
// ? EVENTS // ? EVENTS
cardClick() { cardClick() {