Add a ConfigChanger in the settings menu

This commit is contained in:
Aj - Thomas
2022-05-12 22:16:22 +02:00
parent 84b7d4bbdc
commit ff2fd2febd
2 changed files with 33 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import { Loader, Select } from '@mantine/core';
import { setCookies } from 'cookies-next';
import { useEffect, useState } from 'react';
import { useConfig } from '../../tools/state';
export default function ConfigChanger() {
const { config, loadConfig, setConfig, getConfigs } = useConfig();
const [configList, setConfigList] = useState([] as string[]);
useEffect(() => {
getConfigs().then((configs) => setConfigList(configs));
// setConfig(initialConfig);
}, [config]);
// If configlist is empty, return a loading indicator
if (configList.length === 0) {
return <Loader />;
}
return (
<Select
defaultValue={config.name}
label="Config loader"
onChange={(e) => {
loadConfig(e ?? 'default');
setCookies('config-name', e ?? 'default', { maxAge: 60 * 60 * 24 * 30 });
}}
data={
// If config list is empty, return the current config
configList.length === 0 ? [config.name] : configList
}
/>
);
}

View File

@@ -16,6 +16,7 @@ import { AlertCircle, Settings as SettingsIcon } from 'tabler-icons-react';
import { CURRENT_VERSION, REPO_URL } from '../../data/constants'; import { CURRENT_VERSION, REPO_URL } from '../../data/constants';
import { useConfig } from '../../tools/state'; import { useConfig } from '../../tools/state';
import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch'; import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch';
import ConfigChanger from '../Config/ConfigChanger';
import SaveConfigComponent from '../Config/SaveConfig'; import SaveConfigComponent from '../Config/SaveConfig';
import ModuleEnabler from './ModuleEnabler'; import ModuleEnabler from './ModuleEnabler';
@@ -78,6 +79,7 @@ function SettingsMenu(props: any) {
</Group> </Group>
<ModuleEnabler /> <ModuleEnabler />
<ColorSchemeSwitch /> <ColorSchemeSwitch />
<ConfigChanger />
<SaveConfigComponent /> <SaveConfigComponent />
<Text <Text
style={{ style={{