feat: update deleteLink to use link object directly

This commit is contained in:
Jan Gleytenhoover 2025-01-21 13:13:41 +01:00
parent 88e9ffdb4a
commit e0d9b8295e
Signed by: jank
GPG key ID: 50620ADD22CD330B
2 changed files with 14 additions and 5 deletions

View file

@ -43,7 +43,7 @@
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let element">
<button mat-flat-button color="warn" (click)="deleteLink(element.id)">Delete</button>
<button mat-flat-button color="warn" (click)="deleteLink(element)">Delete</button>
</td>
</ng-container>

View file

@ -54,10 +54,19 @@ export class DashboardComponent {
this.router.navigate(['create-link']);
}
deleteLink(id: string) {
this.linkService.deleteLink(id); // TODO Check if something went wrong
this.links = this.links.filter(link => {
return link.id != id;
deleteLink(link: Link) {
this.dialog.open(ConfirmationModalComponent, {
data: {
title: "Are you sure?",
description: "Are you sure that you want to delete " + link.name + "?",
}
}).afterClosed().subscribe((accepted: boolean) => {
if (accepted) {
this.linkService.deleteLink(link.id); // TODO Check if something went wrong
this.links = this.links.filter(givenLink => {
return givenLink.id != link.id;
});
}
});
}
}