'use client'; import { useEffect, useState } from 'react'; import { loadComponent } from '@/lib/material-components'; import { useOptimizedFetch } from '@/hooks/useOptimizedFetch'; export default function NotificationsPage() { const [componentsLoaded, setComponentsLoaded] = useState(false); const [filter, setFilter] = useState<'unread'>('unread'); useEffect(() => { Promise.all([ loadComponent('elevated-card'), loadComponent('list'), loadComponent('list-item'), loadComponent('icon'), loadComponent('chip-set'), loadComponent('assist-chip'), ]).then(() => { setComponentsLoaded(true); }).catch((err) => { console.error('Error loading components:', err); setComponentsLoaded(true); }); }, []); const { data: notificationsData, loading, refetch } = useOptimizedFetch({ url: '/notifications/', cacheKey: 'notifications_list', cacheTTL: 1 * 60 * 1000, // 1 минута }); if (!componentsLoaded) { return (
Загрузка...
); } const notifications = notificationsData?.results || []; const filteredNotifications = notifications.filter((n: any) => !n.is_read); return (

Уведомления

refetch()}> Обновить
{/* Фильтры */}
setFilter('unread')} />
{loading ? (
Загрузка уведомлений...
) : filteredNotifications.length === 0 ? ( notifications

Нет непрочитанных уведомлений

) : ( {filteredNotifications.map((notification: any) => ( {notification.type === 'info' ? 'info' : 'notifications'} {notification.created_at && ( {new Date(notification.created_at).toLocaleDateString('ru-RU')} )} ))} )}
); }