Files
network-app-web/src/lib/toast.ts
Hammer b0cfa0ab1b fix: resolve all ESLint errors + fix deploy workflow for CI
- Replace all 'any' types with 'unknown' or proper types
- Remove unused imports and variables
- Add comments to empty catch blocks
- Fix Date.now() purity issue in ReportsPage (useMemo)
- Fix fetchNotifications declaration order in NotificationBell
- Restructure MeetingPrepModal effect for setState
- Split Toast exports into separate lib/toast.ts
- Fix constant binary expression in utils.test.ts
- Fix deploy workflow: compose.deploy + DOKPLOY_COMPOSE_ID
2026-01-30 04:37:53 +00:00

37 lines
1.1 KiB
TypeScript

export type ToastType = 'success' | 'error' | 'warning' | 'info';
export interface ToastItem {
id: string;
type: ToastType;
message: string;
duration?: number;
}
// Global toast state
export const toastListeners: ((toasts: ToastItem[]) => void)[] = [];
export const toasts: ToastItem[] = [];
export function notifyListeners() {
toastListeners.forEach(fn => fn([...toasts]));
}
export function showToast(type: ToastType, message: string, duration = 5000) {
const id = Math.random().toString(36).slice(2);
toasts.push({ id, type, message, duration });
notifyListeners();
if (duration > 0) {
setTimeout(() => {
const idx = toasts.findIndex(t => t.id === id);
if (idx >= 0) toasts.splice(idx, 1);
notifyListeners();
}, duration);
}
}
export function toast(message: string) { showToast('info', message); }
toast.success = (msg: string) => showToast('success', msg);
toast.error = (msg: string) => showToast('error', msg, 7000);
toast.warning = (msg: string) => showToast('warning', msg);
toast.info = (msg: string) => showToast('info', msg);