Skip to content

Commit dd5ed62

Browse files
Votre NomVotre Nom
authored andcommitted
load config from json at loading if json config file is present
1 parent bd13909 commit dd5ed62

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed
52 Bytes
Binary file not shown.

examples/server/webui/src/components/Header.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import daisyuiThemes from 'daisyui/src/theming/themes';
66
import { THEMES, CONFIG_DEFAULT, isDev } from '../Config';
77
import { useNavigate } from 'react-router';
88

9-
export const PROMPT_JSON = [
9+
const PROMPT_JSON = [
1010
{
1111
name: '',
1212
lang: '',
@@ -18,7 +18,7 @@ export default function Header() {
1818
const navigate = useNavigate();
1919
const [selectedTheme, setSelectedTheme] = useState(StorageUtils.getTheme());
2020
const { setShowSettings } = useAppContext();
21-
const [selectedConfig, setSelectedConfig] = useState<number>(0);
21+
const [selectedConfig, setSelectedConfig] = useState<number>(-1);
2222

2323
const setTheme = (theme: string) => {
2424
StorageUtils.setTheme(theme);
@@ -43,6 +43,9 @@ export default function Header() {
4343
// @ts-expect-error daisyuiThemes complains about index type, but it should work
4444
daisyuiThemes[selectedTheme]?.['color-scheme'] ?? 'auto'
4545
);
46+
}, [selectedTheme]);
47+
48+
useEffect(() => {
4649
fetch('/prompts.config.json')
4750
.then((response) => response.json())
4851
.then((data) => {
@@ -55,8 +58,23 @@ export default function Header() {
5558
});
5659
}
5760
setPromptSelectOptions(prt);
61+
})
62+
.catch((error) => {
63+
if (isDev) {
64+
console.log(error);
65+
}
5866
});
59-
}, [selectedTheme]);
67+
}, []);
68+
useEffect(() => {
69+
if (promptSelectConfig !== null && selectedConfig == -1) {
70+
setSelectedConfig(0);
71+
//selectPrompt(0);
72+
if (isDev) console.log('Saving config', promptSelectConfig[0].config);
73+
saveConfig(promptSelectConfig[0].config);
74+
resetSettings();
75+
}
76+
}, [promptSelectConfig, selectedConfig, saveConfig, resetSettings]);
77+
6078
const { isGenerating, viewingChat } = useAppContext();
6179
const isCurrConvGenerating = isGenerating(viewingChat?.conv.id ?? '');
6280

@@ -226,13 +244,9 @@ export default function Header() {
226244
aria-label={opt.value}
227245
value={opt.value}
228246
checked={selectedConfig === opt.key}
229-
onChange={(e) => {
230-
selectPrompt(opt.key);
231-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
232-
e.target.checked;
233-
console.log(e.target.checked);
234-
console.log(e);
235-
}}
247+
onChange={(e) =>
248+
e.target.checked && selectPrompt(opt.key)
249+
}
236250
/>
237251
</li>
238252
))}

0 commit comments

Comments
 (0)