import React, { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import { apiFetch } from "../api/client"; import "./Dashboard.css"; const STATUS_LABEL = { planned: 'Запланирован', active: 'Активен', paused: 'Приостановлен', completed: 'Завершён', archived: 'В архиве', }; const STATUS_CLASS = { planned: 'st-planned', active: 'st-active', paused: 'st-paused', completed: 'st-completed', archived: 'st-archived', }; const Dashboard = () => { const navigate = useNavigate(); const [operations, setOperations] = useState([]); const [summary, setSummary] = useState({ active: 0, total: 0, completed_24h: 0 }); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [statusFilter, setStatusFilter] = useState('active'); const [creating, setCreating] = useState(false); const load = async () => { try { setLoading(true); setError(null); const qs = statusFilter ? `?status=${statusFilter}` : ''; const resp = await apiFetch(`/api/v1/operations${qs}`); if (!resp.ok) throw new Error('Не удалось загрузить поиски'); const data = await resp.json(); setOperations(data.items); const sumResp = await apiFetch('/api/v1/operations/summary'); if (sumResp.ok) setSummary(await sumResp.json()); } catch (e) { setError(e.message); } finally { setLoading(false); } }; useEffect(() => { load(); }, [statusFilter]); const openCase = (op) => { // Рабочее пространство операции: анализ по её карточке navigate(`/analysis/${op.case_id}`, { state: { operation: op } }); }; const startNewSearch = () => navigate('/desktop'); return (

ВЕКТОР Активные поиски

{summary.active}
Активных
{summary.total}
Всего операций
{summary.completed_24h}
Завершено за 24 ч
{['active', 'paused', 'completed', '', ].map((s) => ( ))}
{loading &&
Загрузка...
} {error &&
{error}
} {!loading && !error && operations.length === 0 && (
{statusFilter === 'active' ? 'Активных поисков нет. Создайте новый поиск.' : 'Операций в этом статусе нет.'}
)} {!loading && !error && (
{operations.map((op) => (
openCase(op)}>
{STATUS_LABEL[op.status] || op.status}
{op.title}
{op.created_by_name && {op.created_by_name}} {op.updated_at && ( обновлено {new Date(op.updated_at).toLocaleString('ru-RU', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit', })} )}
))}
)}
); }; export default Dashboard;