diff --git a/src/components/RemoteOptionsSection.tsx b/src/components/RemoteOptionsSection.tsx index 9847998..80198eb 100644 --- a/src/components/RemoteOptionsSection.tsx +++ b/src/components/RemoteOptionsSection.tsx @@ -40,8 +40,6 @@ export default function RemoteOptionsSection({ }) { const [optionsJsonStrings, setOptionsJsonStrings] = useState>({}) const [options, setOptions] = useState>>({}) - // @ts-ignore - const [jsonError, setJsonError] = useState(null) const backendsQuery = useQuery({ queryKey: ['backends'], @@ -200,34 +198,21 @@ export default function RemoteOptionsSection({ }) }, [options, setRemoteOptionsJsonString]) + // OptionsSection calls setOptionsJson on every keystroke, including mid-edit + // when the JSON is temporarily invalid. OptionsSection shows "Invalid JSON" + // inline via its own isJsonValid state. The try/catch here just skips the + // update so we keep the last valid parsed options until the user fixes the JSON. useEffect(() => { - let remote: string | null = null - let parseError: string | null = null - const entries = Object.entries(optionsJsonStrings) const newOptions: Record> = {} - - for (const [r, o] of entries) { - remote = r + for (const [r, o] of Object.entries(optionsJsonStrings)) { try { newOptions[r] = JSON.parse(o) as Record - } catch (e) { - console.error(`Error parsing ${remote} options:`, e) - parseError = e instanceof Error ? e.message : 'Unknown error' - break + } catch { + return } } - - if (parseError) { - console.log('[RemoteOptionsSection] parseError', parseError) - setJsonError(`${remote}: ${parseError}`) - return - } - - console.log('[RemoteOptionsSection] setting options to: ', newOptions) - startTransition(() => { setOptions(newOptions) - setJsonError(null) }) }, [optionsJsonStrings]) diff --git a/src/pages/Bisync.tsx b/src/pages/Bisync.tsx index 5693d4c..6073175 100644 --- a/src/pages/Bisync.tsx +++ b/src/pages/Bisync.tsx @@ -195,10 +195,11 @@ export default function Bisync() { const parsedConfig = JSON.parse(configOptionsJsonString) as Record step = 'remote' - const parsedRemote = JSON.parse(remoteOptionsJsonString) as Record< - string, - Record - > + const outerRemote = JSON.parse(remoteOptionsJsonString) as Record + const parsedRemote: Record> = {} + for (const [key, val] of Object.entries(outerRemote)) { + parsedRemote[key] = JSON.parse(val) as Record + } startTransition(() => { setBisyncOptions(parsedBisync) diff --git a/src/pages/Copy.tsx b/src/pages/Copy.tsx index 7a69ab1..adb7e9a 100644 --- a/src/pages/Copy.tsx +++ b/src/pages/Copy.tsx @@ -239,10 +239,11 @@ export default function Copy() { const parsedConfig = JSON.parse(configOptionsJsonString) as Record step = 'remote' - const parsedRemote = JSON.parse(remoteOptionsJsonString) as Record< - string, - Record - > + const outerRemote = JSON.parse(remoteOptionsJsonString) as Record + const parsedRemote: Record> = {} + for (const [key, val] of Object.entries(outerRemote)) { + parsedRemote[key] = JSON.parse(val) as Record + } startTransition(() => { setCopyOptions(parsedCopy) diff --git a/src/pages/Move.tsx b/src/pages/Move.tsx index 2f87a1a..12cf713 100644 --- a/src/pages/Move.tsx +++ b/src/pages/Move.tsx @@ -266,10 +266,11 @@ export default function Move() { const parsedConfig = JSON.parse(configOptionsJsonString) as Record step = 'remote' - const parsedRemote = JSON.parse(remoteOptionsJsonString) as Record< - string, - Record - > + const outerRemote = JSON.parse(remoteOptionsJsonString) as Record + const parsedRemote: Record> = {} + for (const [key, val] of Object.entries(outerRemote)) { + parsedRemote[key] = JSON.parse(val) as Record + } startTransition(() => { setMoveOptions(parsedMove) diff --git a/src/pages/Sync.tsx b/src/pages/Sync.tsx index 65235d9..6598e21 100644 --- a/src/pages/Sync.tsx +++ b/src/pages/Sync.tsx @@ -250,10 +250,11 @@ export default function Sync() { const parsedConfig = JSON.parse(configOptionsJsonString) as Record step = 'remote' - const parsedRemote = JSON.parse(remoteOptionsJsonString) as Record< - string, - Record - > + const outerRemote = JSON.parse(remoteOptionsJsonString) as Record + const parsedRemote: Record> = {} + for (const [key, val] of Object.entries(outerRemote)) { + parsedRemote[key] = JSON.parse(val) as Record + } startTransition(() => { setSyncOptions(parsedSync)