import { useEffect, useState } from 'react'; import { api } from './api'; import type { Health } from './types'; import Workspace from './components/Workspace'; import EvalPage from './components/EvalPage'; import HistoryPage from './components/HistoryPage'; import GpuMonitor from './components/GpuMonitor'; import ComparePage from './components/ComparePage'; import ExperimentsPage from './components/ExperimentsPage'; import Connections from './components/Connections'; import AutomationPage from './components/AutomationPage'; import TrackingPage from './components/TrackingPage'; import { useSettings } from './settings'; import { LangSwitch, useI18n } from './i18n'; import { ThemeSwitch } from './theme'; type Page = 'workspace' | 'eval' | 'compare' | 'experiments' | 'automation' | 'history' | 'tracking'; function readHash(): { page: Page; job?: string; key?: string } { const h = window.location.hash.replace(/^#\/?/, ''); const [p, id] = h.split('/'); if (p === 'eval') return { page: 'eval' }; if (p === 'history') return { page: 'history' }; if (p === 'compare') return { page: 'compare' }; if (p === 'experiments') return { page: 'experiments' }; if (p === 'automation') return { page: 'automation' }; if (p === 'tracking') return { page: 'tracking', key: id }; if (p === 'job' && id) return { page: 'workspace', job: id }; return { page: 'workspace' }; } export default function App() { const { t, lang } = useI18n(); const [route, setRoute] = useState(readHash()); const [health, setHealth] = useState(null); const [healthErr, setHealthErr] = useState(null); useEffect(() => { const onHash = () => setRoute(readHash()); window.addEventListener('hashchange', onHash); return () => window.removeEventListener('hashchange', onHash); }, []); const load = () => api.health().then((h) => { setHealth(h); setHealthErr(null); }) .catch((e) => setHealthErr(String(e.message || e))); const autoActive = !!health?.automation?.active; useEffect(() => { load(); const t = setInterval(load, autoActive ? 5000 : 15000); return () => clearInterval(t); }, [autoActive]); // eslint-disable-line react-hooks/exhaustive-deps // Otomasyon bitince: üstte kalıcı uyarı + (izin verildiyse) masaüstü bildirimi const { prefs } = useSettings(); const fin = health?.automation?.finished || null; const act = health?.automation?.active || null; useEffect(() => { if (!fin) return; let last = ''; try { last = localStorage.getItem('testajani.autoNotified') || ''; } catch { /* yoksay */ } if (last === fin.id) return; try { localStorage.setItem('testajani.autoNotified', fin.id); } catch { /* yoksay */ } if (prefs['auto.notify'] !== false && 'Notification' in window && Notification.permission === 'granted') { try { new Notification(fin.status === 'done' ? t('auto.done.title') : t('auto.done.stopped'), { body: t('auto.notif.body', { d: fin.done, t: fin.total, g: fin.green }), tag: `lta-${fin.id}` }); } catch { /* yoksay */ } } }, [fin?.id]); // eslint-disable-line react-hooks/exhaustive-deps const fmtDur = (sec: number) => { const h = Math.floor(sec / 3600), m = Math.round((sec % 3600) / 60); return h ? t('exp.dur.hm', { h, m }) : sec < 60 ? `${sec} ${t('auto.sec')}` : t('exp.dur.min', { m }); }; const dismiss = async () => { if (fin) { try { await api.seenAuto(fin.id); } catch { /* yoksay */ } load(); } }; const go = (hash: string) => { window.location.hash = hash; }; const ollamaOk = health?.ollama.ok; const pillTitle = [health?.ollama.error || health?.ollama.url || healthErr || '', health?.version ? t('top.version', { v: health.version }) : ''].filter(Boolean).join('\n'); return ( <>
TestAjanı {health?.version && v{health.version.split('-')[0]}}
{act && route.page !== 'automation' && ( {t('nav.automation')} {act.done}/{act.total} )}
{healthErr ? t('top.unreachable') : !health ? t('top.connecting') : ollamaOk ? t('top.ollamaOk', { n: health.ollama.models.length }) : t('top.ollamaDown')} {health && · {t('top.sandbox', { mode: health.sandbox_mode })}}
{fin && (
{fin.status === 'done' ? '✓' : '!'}
{fin.status === 'done' ? t('auto.done.title') : t('auto.done.stopped')}
{t('auto.done.text', { t: fin.total, d: fin.done, g: fin.green, f: fin.failed, s: fmtDur(fin.duration_s) })}
)} {route.page === 'workspace' && } {route.page === 'eval' && } {route.page === 'compare' && } {route.page === 'experiments' && } {route.page === 'automation' && } {route.page === 'history' && } {route.page === 'tracking' && } ); }