mirror of
https://github.com/opelly27/WinStudentGoalTracker.git
synced 2026-05-20 11:07:41 +00:00
3 ui updates
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
|
||||
export type ToastType = 'success' | 'error' | 'info';
|
||||
|
||||
export interface Toast {
|
||||
id: number;
|
||||
message: string;
|
||||
type: ToastType;
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ToastService {
|
||||
private nextId = 0;
|
||||
readonly toasts = signal<Toast[]>([]);
|
||||
|
||||
show(message: string, type: ToastType = 'success') {
|
||||
const id = ++this.nextId;
|
||||
this.toasts.update(list => [...list, { id, message, type }]);
|
||||
setTimeout(() => this.dismiss(id), 3000);
|
||||
}
|
||||
|
||||
dismiss(id: number) {
|
||||
this.toasts.update(list => list.filter(t => t.id !== id));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user