import { useEffect, useState } from 'react'; import { getFileContents } from '../webdav'; interface GeneralPageProps { config: any; setConfig: (config: any) => void; } export default function GeneralPage({ config, setConfig }: GeneralPageProps) { const [timezones, setTimezones] = useState(null); const [tzError, setTzError] = useState(false); useEffect(() => { getFileContents('/.sys/timezones.json') .then(async (blob) => { const parsed = JSON.parse(await blob.text()); if (Array.isArray(parsed)) { setTimezones(parsed.map((e: any) => (typeof e === 'string' ? e : String(e.name ?? e.value ?? e)))); } else if (parsed && typeof parsed === 'object') { setTimezones(Object.keys(parsed)); } else { setTzError(true); } }) .catch(() => setTzError(true)); }, []); const updateSetting = (path: string[], value: any) => { const newConfig = JSON.parse(JSON.stringify(config)); let current = newConfig; for (let i = 0; i < path.length - 1; i++) { current = current[path[i]]; } current[path[path.length - 1]] = value; setConfig(newConfig); }; const general = config.general || {}; return (

General Settings

{!tzError && timezones ? ( ) : ( updateSetting(['general', 'timezone'], e.target.value)} placeholder={timezones === null && !tzError ? 'Loading…' : 'America/Los_Angeles'} disabled={timezones === null && !tzError} className="w-full px-3 py-2 border border-neutral-300 rounded-lg disabled:opacity-50" /> )}
updateSetting(['general', 'country'], e.target.value)} placeholder="US" className="w-full px-3 py-2 border border-neutral-300 rounded-lg" />
updateSetting(['general', 'devicename'], e.target.value)} className="w-full px-3 py-2 border border-neutral-300 rounded-lg" />
); }