diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts
index 1af3fbf..a2727b6 100644
--- a/src/app/dashboard/dashboard.component.ts
+++ b/src/app/dashboard/dashboard.component.ts
@@ -9,6 +9,7 @@ import { Link } from '../models/link';
import { MatButtonModule } from '@angular/material/button';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { ConfirmationModalComponent } from '../confirmation-modal/confirmation-modal.component';
+import { MatSnackBar } from '@angular/material/snack-bar';
@Component({
selector: 'app-dashboard',
@@ -20,7 +21,7 @@ export class DashboardComponent {
public links: Link[] = [];
displayedColumns: string[] = ['id', 'name', 'link', 'shortLink', 'actions'];
- constructor(private linkService: LinkService, private router: Router, private dialog: MatDialog) { };
+ constructor(private linkService: LinkService, private router: Router, private dialog: MatDialog, private snackBar: MatSnackBar) { };
copyLink(id: string) {
navigator.clipboard.writeText(this.getShortLink(id));
@@ -62,10 +63,21 @@ export class DashboardComponent {
}
}).afterClosed().subscribe((accepted: boolean) => {
if (accepted) {
- this.linkService.deleteLink(link.id); // TODO Check if something went wrong
+ this.linkService.deleteLink(link.id).catch(() => {
+ const errorNotification = this.snackBar.open("Something went wrong.");
+ setTimeout(() => {
+ errorNotification.dismiss();
+ }, 5000);
+ });
+
this.links = this.links.filter(givenLink => {
return givenLink.id != link.id;
});
+
+ const notification = this.snackBar.open(link.name + " was deleted.");
+ setTimeout(() => {
+ notification.dismiss();
+ }, 2000);
}
});
}
diff --git a/src/app/service/link.service.ts b/src/app/service/link.service.ts
index 89b9329..09d5dec 100644
--- a/src/app/service/link.service.ts
+++ b/src/app/service/link.service.ts
@@ -18,8 +18,8 @@ export class LinkService {
return this.pb.collection('links').getOne(id);
}
- deleteLink(id: string) {
- this.pb.collection('links').delete(id);
+ deleteLink(id: string): Promise {
+ return this.pb.collection('links').delete(id);
}
createLink(link: any): Promise {