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'>('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'; } return log.level === filter; }) .sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()); const renderNotificationDetails = (details: NotificationDetails) => { if (details.type === 'update') { return (

{details.message}

Current Version: {details.currentVersion}

Latest Version: {details.latestVersion}

Branch: {details.branch}

); } return details.message ?

{details.message}

: null; }; return (
{filteredLogs.length === 0 ? (

No Notifications

You're all caught up!

) : ( filteredLogs.map((log) => (

{log.message}

{log.details && renderNotificationDetails(log.details as NotificationDetails)}
)) )}
); }; export default NotificationsTab;