ldc-showroom/classes/Toast.ts

42 lines
1.3 KiB
TypeScript

import log from "electron-log";
export enum ToastTypeEnum {
default = "default",
success = "success",
info = "info",
error = "error",
warning = "warning",
}
export const ToastType = Object.freeze({
default: ToastTypeEnum.default,
success: ToastTypeEnum.success,
info: ToastTypeEnum.info,
error: ToastTypeEnum.error,
warning: ToastTypeEnum.warning,
});
export default abstract class Toast {
/** Affiche un toast message */
public static toast(message: string, type: ToastTypeEnum = ToastType.default, title: string|null = null):void {
const toast = useState("toastMessage").value as (message: string, type: ToastTypeEnum, title:string|null) => void;
toast(message, type, title);
const prefix: string = `${type.toLowerCase()} : `;
switch (type) {
case ToastType.info:
log.info(prefix, message);
break;
case ToastType.warning:
log.warn(prefix, message);
break;
case ToastType.error:
log.error(prefix, message);
break;
case ToastType.default:
case ToastType.success:
default:
log.verbose(prefix, message);
}
}
}