import { type JSX, Match, Show, Switch, createEffect, createSignal } from 'solid-js'; import { InfoCircleIcon } from '@untitled-theme/icons-solid'; import TimeAgo from '../../TimeAgo'; import { PausableTimer } from '~utils/PausableTimer'; type NotificationComponentProps = Core.Notification & { overlay: boolean; }; type NotificationType = ''; function IconFromNotificationType(type: NotificationType): (props: JSX.HTMLAttributes) => JSX.Element { switch (type) { // case NotificationType.Alert: // return AlertTriangleIcon as any; // case NotificationType.Download: // return FolderDownloadIcon as any; // case NotificationType.DownloadSuccess: // return FolderCheckIcon as any; // case NotificationType.DownloadError: // return FolderXIcon as any; // case NotificationType.Refresh: // return RefreshCcw02Icon as any; // case NotificationType.Success: // return CheckCircleIcon as any; // case NotificationType.Info: default: return InfoCircleIcon as any; } } function ColorFromNotificationType(type: NotificationType): string { switch (type) { // case NotificationType.Info: // case NotificationType.Refresh: // return 'text-brand'; // case NotificationType.Alert: // case NotificationType.DownloadError: // return 'text-danger'; // case NotificationType.DownloadSuccess: // case NotificationType.Success: // return 'text-success'; // case NotificationType.Download: default: return 'text-fg-primary'; } } const TOTAL_SECONDS = 7; function NotificationOverlayComponent(props: NotificationComponentProps) { const [disappearing, setDisappearing] = createSignal(true); const [timer, setTimer] = createSignal(); const [visible, setVisible] = createSignal(true); const [secondsLeft, setSecondsLeft] = createSignal(TOTAL_SECONDS); createEffect(() => { setDisappearing(props.progress === undefined); if (props.progress !== undefined && props.progress >= 1) { setVisible(false); return; } if (disappearing()) { setTimer(new PausableTimer(onInterval, 1000, true)); return; } if (timer()) { timer()?.stop(); setTimer(undefined); } }); // onMount(() => { // setVisible(true); // }); function onInterval() { if (secondsLeft() <= 0) { hide(); return; } setSecondsLeft(secondsLeft() - 1); } function hide() { timer()?.stop(); setVisible(false); setTimer(undefined); } function onEnter() { timer()?.pause(); } function onLeave() { timer()?.resume(); } return ( //
onEnter()} onMouseLeave={() => onLeave()} class="flex flex-col overflow-hidden rounded-lg bg-component-bg" >
// ); } function NotificationPopupComponent(props: NotificationComponentProps) { return (
{IconFromNotificationType(props.notification_type)({ class: `w-6 h-6 ${ColorFromNotificationType(props.notification_type)}`, })}
{props.title} {props.message}
); } function NotificationComponent(props: NotificationComponentProps) { return ( ); } export default NotificationComponent;