import React, { useState } from 'react'; import { RefreshCw, Save } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { useAppContext } from '../context/AppContext'; import RecursiveConfig from '../components/RecursiveConfig'; function setPath(obj: any, path: string, value: any) { const keys = path.split('.') const next = JSON.parse(JSON.stringify(obj || {})) let cur = next for (let i = 0; i < keys.length - 1; i++) { const k = keys[i] if (typeof cur[k] !== 'object' || cur[k] === null) cur[k] = {} cur = cur[k] } cur[keys[keys.length - 1]] = value return next } const Config: React.FC = () => { const { t } = useTranslation(); const { cfg, setCfg, cfgRaw, setCfgRaw, loadConfig, hotReloadFieldDetails, q } = useAppContext(); const [showRaw, setShowRaw] = useState(false); async function saveConfig() { try { const payload = showRaw ? JSON.parse(cfgRaw) : cfg; const r = await fetch(`/webui/api/config${q}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload), }); alert(await r.text()); } catch (e) { alert('Failed to save config: ' + e); } } return (