1.2 #11
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 { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||||
import { ConfirmationModalComponent } from '../confirmation-modal/confirmation-modal.component';
|
import { ConfirmationModalComponent } from '../confirmation-modal/confirmation-modal.component';
|
||||||
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-dashboard',
|
selector: 'app-dashboard',
|
||||||
|
@ -20,7 +21,7 @@ export class DashboardComponent {
|
||||||
public links: Link[] = [];
|
public links: Link[] = [];
|
||||||
displayedColumns: string[] = ['id', 'name', 'link', 'shortLink', 'actions'];
|
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) {
|
copyLink(id: string) {
|
||||||
navigator.clipboard.writeText(this.getShortLink(id));
|
navigator.clipboard.writeText(this.getShortLink(id));
|
||||||
|
@ -62,10 +63,21 @@ export class DashboardComponent {
|
||||||
}
|
}
|
||||||
}).afterClosed().subscribe((accepted: boolean) => {
|
}).afterClosed().subscribe((accepted: boolean) => {
|
||||||
if (accepted) {
|
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 => {
|
this.links = this.links.filter(givenLink => {
|
||||||
return givenLink.id != link.id;
|
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);
|
return this.pb.collection('links').getOne<Link>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteLink(id: string) {
|
deleteLink(id: string): Promise<boolean> {
|
||||||
this.pb.collection('links').delete(id);
|
return this.pb.collection('links').delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
createLink(link: any): Promise<RecordModel> {
|
createLink(link: any): Promise<RecordModel> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue