import React, { useState } from 'react'; import { motion } from 'framer-motion'; import { logStore } from '~/lib/stores/logs'; import { useStore } from '@nanostores/react'; import { formatDistanceToNow } from 'date-fns'; import { classNames } from '~/utils/classNames'; interface NotificationDetails { type?: string; message?: string; currentVersion?: string; latestVersion?: string; branch?: string; updateUrl?: string; } const NotificationsTab = () => { const [filter, setFilter] = useState<'all' | 'error' | 'warning' | 'update'>('all'); const logs = useStore(logStore.logs); const handleClearNotifications = () => { logStore.clearLogs(); }; const handleUpdateAction = (updateUrl: string) => { window.open(updateUrl, '_blank'); }; const filteredLogs = Object.values(logs) .filter((log) => { if (filter === 'all') { return log.level === 'error' || log.level === 'warning' || log.details?.type === 'update'; } if (filter === 'update') { return log.details?.type === 'update'; } return log.level === filter; }) .sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()); const getNotificationStyle = (log: (typeof filteredLogs)[0]) => { if (log.details?.type === 'update') { return { border: 'border-purple-200 dark:border-purple-900/50', bg: 'bg-purple-50 dark:bg-purple-900/20', icon: 'i-ph:arrow-circle-up text-purple-600 dark:text-purple-400', text: 'text-purple-900 dark:text-purple-300', }; } if (log.level === 'error') { return { border: 'border-red-200 dark:border-red-900/50', bg: 'bg-red-50 dark:bg-red-900/20', icon: 'i-ph:warning-circle text-red-600 dark:text-red-400', text: 'text-red-900 dark:text-red-300', }; } return { border: 'border-yellow-200 dark:border-yellow-900/50', bg: 'bg-yellow-50 dark:bg-yellow-900/20', icon: 'i-ph:warning text-yellow-600 dark:text-yellow-400', text: 'text-yellow-900 dark:text-yellow-300', }; }; const renderNotificationDetails = (details: NotificationDetails) => { if (details.type === 'update') { return (
{details.message}
Current Version: {details.currentVersion}
Latest Version: {details.latestVersion}
Branch: {details.branch}
{details.message}
: null; }; return (You're all caught up!