prvi kod za live uporabu
Some checks failed
ERP CI Pipeline / test (push) Has been cancelled

This commit is contained in:
mariomitte
2026-07-09 21:21:17 +02:00
parent 857bb65d52
commit 5d39e048ba
239 changed files with 25151 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import { signal } from '@preact/signals';
export type ToastType = 'success' | 'error' | 'info' | 'warning';
export interface ToastMessage {
id: string;
type: ToastType;
message: string;
durationMs: number;
}
export const toastMessages = signal<ToastMessage[]>([]);
function getToastMessages(): ToastMessage[] {
return Array.isArray(toastMessages.value) ? toastMessages.value : [];
}
function nextId(): string {
return `${Date.now()}-${Math.floor(Math.random() * 100000)}`;
}
export function removeToast(id: string): void {
toastMessages.value = getToastMessages().filter((toast) => toast.id !== id);
}
export function pushToast(
message: string,
type: ToastType = 'info',
durationMs = 3000
): string {
const id = nextId();
toastMessages.value = [{ id, type, message, durationMs }, ...getToastMessages()].slice(0, 5);
return id;
}
export function useToast() {
return {
success: (message: string, durationMs?: number) => pushToast(message, 'success', durationMs),
error: (message: string, durationMs?: number) => pushToast(message, 'error', durationMs),
info: (message: string, durationMs?: number) => pushToast(message, 'info', durationMs),
warning: (message: string, durationMs?: number) => pushToast(message, 'warning', durationMs),
dismiss: removeToast,
};
}