From 3e0b17ebe61edf69f3f9f3d22189338e23170240 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Tue, 21 Jan 2025 13:25:35 +0100 Subject: [PATCH] feat(dashboard): add snack bar notifications for link actions --- src/app/dashboard/dashboard.component.ts | 16 ++++++++++++++-- src/app/service/link.service.ts | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) 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 {