This commit is contained in:
Chris Chen
2026-06-20 17:51:33 -07:00
parent f55807fa7d
commit 3558c67fd7
55 changed files with 3140 additions and 85 deletions
@@ -0,0 +1,42 @@
import { Injectable, signal } from '@angular/core';
export type ToastType = 'error' | 'success' | 'info';
export interface Toast {
id: number;
type: ToastType;
message: string;
}
/**
* Lightweight, dependency-free toast/notification store. A single
* ToastContainerComponent (mounted in the app root) renders whatever this holds.
*/
@Injectable({ providedIn: 'root' })
export class ToastService {
private counter = 0;
readonly toasts = signal<Toast[]>([]);
error(message: string): void {
this.show('error', message);
}
success(message: string): void {
this.show('success', message);
}
info(message: string): void {
this.show('info', message);
}
dismiss(id: number): void {
this.toasts.update(list => list.filter(toast => toast.id !== id));
}
private show(type: ToastType, message: string): void {
const id = ++this.counter;
this.toasts.update(list => [...list, { id, type, message }]);
const autoDismissMs = type === 'error' ? 8000 : 4000;
setTimeout(() => this.dismiss(id), autoDismissMs);
}
}