import { useQuery } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { Link } from 'react-router'; import { fetchReadiness, readyQueryKey } from '@/api/health'; import { fetchMeta, metaQueryKey } from '@/api/meta'; import { Badge, Button, Card } from '@/components/ui/primitives'; import { StatBytes, StatRow } from '@/components/ui/StatRow'; import { supportedLanguages, type SupportedLanguage } from '@/i18n'; import { useApiErrorMessage } from '@/lib/useApiErrorMessage'; import { useUiStore } from '@/stores/ui'; /** Публичная страница состояния инстанса: мета, healthz/readyz, тема и язык. */ export default function StatusPage() { const { t, i18n } = useTranslation(); const describeError = useApiErrorMessage(); const theme = useUiStore((state) => state.theme); const toggleTheme = useUiStore((state) => state.toggleTheme); const locale = i18n.resolvedLanguage ?? 'ru'; const meta = useQuery({ queryKey: metaQueryKey, queryFn: ({ signal }) => fetchMeta(signal), retry: 1, }); const readiness = useQuery({ queryKey: readyQueryKey, queryFn: ({ signal }) => fetchReadiness(signal), retry: 1, refetchInterval: 30_000, }); const online = readiness.isSuccess || meta.isSuccess; const schemaReady = readiness.data?.checks['database'] === 'ok'; const changeLanguage = (language: SupportedLanguage): void => { window.localStorage.setItem('glchat.language', language); void i18n.changeLanguage(language); }; return (
{t('app.tagline')}
{t('status.description')}
{meta.isPending ? ({t('status.connecting')}
) : null} {meta.isError ? ({describeError(meta.error)}