From aa4ce3478a432b90d5878e4c428c8f8e2410eda2 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 16 Oct 2024 23:03:51 -0700 Subject: [PATCH] update styles in settings page --- .../void/src/sidebar/SidebarSettings.tsx | 115 +++++++++++------- .../void/src/sidebar/contextForConfig.tsx | 2 +- 2 files changed, 72 insertions(+), 45 deletions(-) diff --git a/extensions/void/src/sidebar/SidebarSettings.tsx b/extensions/void/src/sidebar/SidebarSettings.tsx index a8dc040d..47d657f0 100644 --- a/extensions/void/src/sidebar/SidebarSettings.tsx +++ b/extensions/void/src/sidebar/SidebarSettings.tsx @@ -5,49 +5,55 @@ import { configFields, useVoidConfig, VoidConfigField } from "./contextForConfig const SettingOfFieldAndParam = ({ field, param }: { field: VoidConfigField, param: string }) => { const { voidConfig, partialVoidConfig, voidConfigInfo, setConfigParam } = useVoidConfig() + const { defaultVal, description } = voidConfigInfo[field][param] const [val, setVal] = useState(partialVoidConfig[field]?.[param]) const { enumArr } = voidConfigInfo[field][param] - const updateState = (e: React.ChangeEvent) => { setVal(e.target.value); }; - const commitConfigParam = () => { if (val) setConfigParam(field, param, val); }; + const updateState = (newValue: string | undefined) => { + setVal(newValue) + if (newValue) + setConfigParam(field, param, newValue) + } - // string - if (enumArr === undefined) { - return ( -
- - -
- ) - } - // enum - else { - return ( -
- - -
- ) - } + const resetButton = + + const inputElement = enumArr === undefined ? + // string + ( updateState(e.target.value)} + />) + : + // enum + () + + return
+ + {description} +
+ {inputElement} + {resetButton} +
+
} export const SidebarSettings = () => { @@ -55,17 +61,38 @@ export const SidebarSettings = () => { const { voidConfig, voidConfigInfo } = useVoidConfig() const current_field = voidConfig.default['whichApi'] as VoidConfigField - const params = Object.keys(voidConfigInfo[current_field]) + return ( -
- {params.map((param) => ( +
+ + {/* choose the field */} +
- ))} +
+ +
+ + {/* render all fields, but hide the ones not visible for fast tab switching */} + {configFields.map(field => { + return
+ {Object.keys(voidConfigInfo[field]).map((param) => ( + + ))} +
+ })} + +
) } diff --git a/extensions/void/src/sidebar/contextForConfig.tsx b/extensions/void/src/sidebar/contextForConfig.tsx index 14b1cce7..30c2219d 100644 --- a/extensions/void/src/sidebar/contextForConfig.tsx +++ b/extensions/void/src/sidebar/contextForConfig.tsx @@ -41,7 +41,7 @@ const voidConfigInfo: Record< > = { default: { whichApi: configEnum( - "Choose an API provider.", + "API Provider.", 'anthropic', configFields, ),