mirror of
https://github.com/averel10/crypto_clash.git
synced 2026-03-12 19:08:11 +01:00
Refactor Clash component to use GameModal for game interactions, remove Hello World page, and implement toast notifications for error handling
This commit is contained in:
47
crypto_clash_frontend/app/lib/toast.ts
Normal file
47
crypto_clash_frontend/app/lib/toast.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
export type ToastType = 'success' | 'error' | 'info' | 'warning';
|
||||
|
||||
export interface Toast {
|
||||
id: string;
|
||||
message: string;
|
||||
type: ToastType;
|
||||
duration?: number;
|
||||
}
|
||||
|
||||
let toastListener: ((toast: Toast) => void) | null = null;
|
||||
let toastId = 0;
|
||||
|
||||
export function setToastListener(listener: (toast: Toast) => void) {
|
||||
toastListener = listener;
|
||||
}
|
||||
|
||||
export function showToast(message: string, type: ToastType = 'info', duration = 4000) {
|
||||
const id = String(toastId++);
|
||||
const toast: Toast = {
|
||||
id,
|
||||
message,
|
||||
type,
|
||||
duration,
|
||||
};
|
||||
|
||||
if (toastListener) {
|
||||
toastListener(toast);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
export function showSuccessToast(message: string, duration?: number) {
|
||||
return showToast(message, 'success', duration);
|
||||
}
|
||||
|
||||
export function showErrorToast(message: string, duration?: number) {
|
||||
return showToast(message, 'error', duration);
|
||||
}
|
||||
|
||||
export function showInfoToast(message: string, duration?: number) {
|
||||
return showToast(message, 'info', duration);
|
||||
}
|
||||
|
||||
export function showWarningToast(message: string, duration?: number) {
|
||||
return showToast(message, 'warning', duration);
|
||||
}
|
||||
Reference in New Issue
Block a user