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