import { useState, useEffect } from 'react'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { toast } from 'sonner'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { useClient } from 'hooks/useClient'; type SttConfig = { url: string; }; export const STTSection = () => { const client = useClient(); const queryClient = useQueryClient(); const { data: config, isLoading } = useQuery({ queryKey: ['STT_CONFIG'], queryFn: () => client.get('/server-settings/stt'), }); const [url, setUrl] = useState('http://localhost:64201'); const [isSaving, setIsSaving] = useState(false); const [isTesting, setIsTesting] = useState(false); useEffect(() => { if (!config) return; setUrl(config.url); }, [config]); const handleSave = async () => { if (isSaving) return; setIsSaving(true); try { await client.put('/server-settings/stt', { url }); queryClient.invalidateQueries({ queryKey: ['STT_CONFIG'] }); toast.success('STT settings saved'); } catch { toast.error('Failed to save STT settings'); } finally { setIsSaving(false); } }; const handleTest = async () => { if (isTesting) return; setIsTesting(true); try { const res = await client.post<{ success?: boolean; error?: string }>('/server-settings/stt/test', { url }); if (res.error) { toast.error(res.error); } else { toast.success('Whisper server is reachable'); } } catch (err: unknown) { const raw = (err as { message?: string })?.message; let msg = 'Connection failed'; try { if (raw) msg = JSON.parse(raw).error ?? msg; } catch { /* ignore */ } toast.error(msg); } finally { setIsTesting(false); } }; if (isLoading) return

Loading...

; return (
); };