mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-13 00:45:47 +01:00
Fix config changer
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
"configSelect": {
|
"configSelect": {
|
||||||
"label": "Config loader"
|
"label": "Config loader",
|
||||||
|
"loadingNew": "Loading your config...",
|
||||||
|
"pleaseWait": "Please wait until your new config is loaded"
|
||||||
},
|
},
|
||||||
"modal": {
|
"modal": {
|
||||||
"title": "Choose the name of your new config",
|
"title": "Choose the name of your new config",
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { Center, Loader, Select, Tooltip } from '@mantine/core';
|
import { Center, Dialog, Loader, Notification, Select, Tooltip } from '@mantine/core';
|
||||||
|
import { useToggle } from '@mantine/hooks';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { setCookie } from 'cookies-next';
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useConfigContext } from '../../config/provider';
|
import { useConfigContext } from '../../config/provider';
|
||||||
@@ -11,19 +13,22 @@ export default function ConfigChanger() {
|
|||||||
|
|
||||||
const { data: configs, isLoading, isError } = useConfigsQuery();
|
const { data: configs, isLoading, isError } = useConfigsQuery();
|
||||||
const [activeConfig, setActiveConfig] = useState(configName);
|
const [activeConfig, setActiveConfig] = useState(configName);
|
||||||
|
const [isRefreshing, toggle] = useToggle();
|
||||||
|
|
||||||
const onConfigChange = (value: string) => {
|
const onConfigChange = (value: string) => {
|
||||||
// TODO: check what should happen here with @manuel-rw
|
// TODO: check what should happen here with @manuel-rw
|
||||||
// Wheter it should check for the current url and then load the new config only on index
|
// Wheter it should check for the current url and then load the new config only on index
|
||||||
// Or it should always load the selected config and open index or ? --> change url to page
|
// Or it should always load the selected config and open index or ? --> change url to page
|
||||||
setActiveConfig(value);
|
setCookie('config-name', value ?? 'default', {
|
||||||
/*
|
|
||||||
loadConfig(e ?? 'default');
|
|
||||||
setCookie('config-name', e ?? 'default', {
|
|
||||||
maxAge: 60 * 60 * 24 * 30,
|
maxAge: 60 * 60 * 24 * 30,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
});
|
});
|
||||||
*/
|
setActiveConfig(value);
|
||||||
|
toggle();
|
||||||
|
// Use timeout to wait for the cookie to be set
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.reload();
|
||||||
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
// If configlist is empty, return a loading indicator
|
// If configlist is empty, return a loading indicator
|
||||||
@@ -38,12 +43,26 @@ export default function ConfigChanger() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<Select
|
<Select
|
||||||
label={t('configSelect.label')}
|
label={t('configSelect.label')}
|
||||||
value={activeConfig}
|
value={activeConfig}
|
||||||
onChange={onConfigChange}
|
onChange={onConfigChange}
|
||||||
data={configs}
|
data={configs}
|
||||||
/>
|
/>
|
||||||
|
<Dialog
|
||||||
|
position={{ top: 0, left: 0 }}
|
||||||
|
unstyled
|
||||||
|
opened={isRefreshing}
|
||||||
|
onClose={() => toggle()}
|
||||||
|
size="lg"
|
||||||
|
radius="md"
|
||||||
|
>
|
||||||
|
<Notification loading title={t('configSelect.loadingNew')} radius="md" disallowClose>
|
||||||
|
{t('configSelect.pleaseWait')}
|
||||||
|
</Notification>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user