feat(dashboard): add snack bar notifications for link actions
This commit is contained in:
		
					parent
					
						
							
								e0d9b8295e
							
						
					
				
			
			
				commit
				
					
						3e0b17ebe6
					
				
			
		
					 2 changed files with 16 additions and 4 deletions
				
			
		|  | @ -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); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
|  |  | |||
|  | @ -18,8 +18,8 @@ export class LinkService { | |||
|     return this.pb.collection('links').getOne<Link>(id); | ||||
|   } | ||||
| 
 | ||||
|   deleteLink(id: string) { | ||||
|     this.pb.collection('links').delete(id); | ||||
|   deleteLink(id: string): Promise<boolean> { | ||||
|     return this.pb.collection('links').delete(id); | ||||
|   } | ||||
| 
 | ||||
|   createLink(link: any): Promise<RecordModel> { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue