Files
Homarr/src/components/Config/ConfigChanger.tsx

44 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-05-12 22:19:51 +02:00
import { Center, Loader, Select, Tooltip } from '@mantine/core';
2022-07-22 16:20:47 +02:00
import { setCookie } from 'cookies-next';
2022-08-18 21:46:46 +02:00
import { t } from 'i18next';
import { useEffect, useState } from 'react';
import { useConfig } from '../../tools/state';
export default function ConfigChanger() {
const { config, loadConfig, setConfig, getConfigs } = useConfig();
const [configList, setConfigList] = useState<string[]>([]);
const [value, setValue] = useState(config.name);
useEffect(() => {
getConfigs().then((configs) => setConfigList(configs));
}, [config]);
// If configlist is empty, return a loading indicator
if (configList.length === 0) {
2022-05-12 22:19:51 +02:00
return (
<Tooltip label={"Loading your configs. This doesn't load in vercel."}>
<Center>
2022-05-12 22:19:51 +02:00
<Loader />
</Center>
</Tooltip>
2022-05-12 22:19:51 +02:00
);
}
// return <Select data={[{ value: '1', label: '1' },]} onChange={(e) => console.log(e)} value="1" />;
return (
<Select
2022-08-18 21:46:46 +02:00
label={t('settings.tabs.common.settings.configChanger.configSelect.label')}
value={value}
defaultValue={config.name}
onChange={(e) => {
loadConfig(e ?? 'default');
2022-07-22 16:20:47 +02:00
setCookie('config-name', e ?? 'default', {
maxAge: 60 * 60 * 24 * 30,
sameSite: 'strict',
});
}}
data={
// If config list is empty, return the current config
configList.length === 0 ? [config.name] : configList
}
/>
);
}