Switch to angular
This commit is contained in:
64
frontend/src/app/services/notification.service.ts
Normal file
64
frontend/src/app/services/notification.service.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NotificationService {
|
||||
|
||||
constructor(private snackBar: MatSnackBar) {}
|
||||
|
||||
showSuccess(message: string, duration: number = 3000): void {
|
||||
this.snackBar.open(message, 'Close', {
|
||||
duration,
|
||||
panelClass: ['success-snackbar'],
|
||||
horizontalPosition: 'center',
|
||||
verticalPosition: 'bottom'
|
||||
});
|
||||
}
|
||||
|
||||
showError(message: string, duration: number = 5000): void {
|
||||
this.snackBar.open(message, 'Close', {
|
||||
duration,
|
||||
panelClass: ['error-snackbar'],
|
||||
horizontalPosition: 'center',
|
||||
verticalPosition: 'bottom'
|
||||
});
|
||||
}
|
||||
|
||||
showInfo(message: string, duration: number = 3000): void {
|
||||
this.snackBar.open(message, 'Close', {
|
||||
duration,
|
||||
panelClass: ['info-snackbar'],
|
||||
horizontalPosition: 'center',
|
||||
verticalPosition: 'bottom'
|
||||
});
|
||||
}
|
||||
|
||||
showWarning(message: string, duration: number = 4000): void {
|
||||
this.snackBar.open(message, 'Close', {
|
||||
duration,
|
||||
panelClass: ['warning-snackbar'],
|
||||
horizontalPosition: 'center',
|
||||
verticalPosition: 'bottom'
|
||||
});
|
||||
}
|
||||
|
||||
showConfirmation(message: string, action: string = 'Confirm'): Promise<boolean> {
|
||||
const snackBarRef = this.snackBar.open(message, action, {
|
||||
duration: 10000,
|
||||
panelClass: ['confirmation-snackbar'],
|
||||
horizontalPosition: 'center',
|
||||
verticalPosition: 'bottom'
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
snackBarRef.onAction().subscribe(() => resolve(true));
|
||||
snackBarRef.afterDismissed().subscribe((info) => {
|
||||
if (!info.dismissedByAction) {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user