mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 16:05:47 +01:00
🐛 Fix config changer and critical bug in copy config
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"configSelect": {
|
"configSelect": {
|
||||||
"label": "Config changer",
|
"label": "Config changer",
|
||||||
|
"description": "{{configCount}} configurations are available",
|
||||||
"loadingNew": "Loading your config...",
|
"loadingNew": "Loading your config...",
|
||||||
"pleaseWait": "Please wait until your new config is loaded!"
|
"pleaseWait": "Please wait until your new config is loaded!"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,15 +3,17 @@ import { useToggle } from '@mantine/hooks';
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { setCookie } from 'cookies-next';
|
import { setCookie } from 'cookies-next';
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useConfigContext } from '../../config/provider';
|
import { useConfigContext } from '../../config/provider';
|
||||||
|
|
||||||
export default function ConfigChanger() {
|
export default function ConfigChanger() {
|
||||||
const { t } = useTranslation('settings/general/config-changer');
|
const router = useRouter();
|
||||||
const { name: configName } = useConfigContext();
|
|
||||||
// const loadConfig = useConfigStore((x) => x.loadConfig);
|
|
||||||
|
|
||||||
const { data: configs, isLoading, isError } = useConfigsQuery();
|
const { t } = useTranslation('settings/general/config-changer');
|
||||||
|
const { name: configName, setConfigName } = useConfigContext();
|
||||||
|
|
||||||
|
const { data: configs, isLoading } = useConfigsQuery();
|
||||||
const [activeConfig, setActiveConfig] = useState(configName);
|
const [activeConfig, setActiveConfig] = useState(configName);
|
||||||
const [isRefreshing, toggle] = useToggle();
|
const [isRefreshing, toggle] = useToggle();
|
||||||
|
|
||||||
@@ -22,14 +24,13 @@ export default function ConfigChanger() {
|
|||||||
});
|
});
|
||||||
setActiveConfig(value);
|
setActiveConfig(value);
|
||||||
toggle();
|
toggle();
|
||||||
// Use timeout to wait for the cookie to be set
|
|
||||||
setTimeout(() => {
|
router.push(`/${value}`);
|
||||||
window.location.reload();
|
setConfigName(value);
|
||||||
}, 1000);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// If configlist is empty, return a loading indicator
|
// If configlist is empty, return a loading indicator
|
||||||
if (isLoading || !configs || configs?.length === 0 || !configName) {
|
if (isLoading || !configs || configs.length === 0 || !configName) {
|
||||||
return (
|
return (
|
||||||
<Tooltip label={"Loading your configs. This doesn't load in vercel."}>
|
<Tooltip label={"Loading your configs. This doesn't load in vercel."}>
|
||||||
<Center>
|
<Center>
|
||||||
@@ -43,6 +44,7 @@ export default function ConfigChanger() {
|
|||||||
<>
|
<>
|
||||||
<Select
|
<Select
|
||||||
label={t('configSelect.label')}
|
label={t('configSelect.label')}
|
||||||
|
description={t('configSelect.description', { configCount: configs.length })}
|
||||||
value={activeConfig}
|
value={activeConfig}
|
||||||
onChange={onConfigChange}
|
onChange={onConfigChange}
|
||||||
data={configs}
|
data={configs}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ export default function ConfigActions() {
|
|||||||
if (!config) return null;
|
if (!config) return null;
|
||||||
|
|
||||||
const handleDownload = () => {
|
const handleDownload = () => {
|
||||||
// TODO: remove secrets
|
|
||||||
fileDownload(JSON.stringify(config, null, '\t'), `${config?.configProperties.name}.json`);
|
fileDownload(JSON.stringify(config, null, '\t'), `${config?.configProperties.name}.json`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
|
import Consola from 'consola';
|
||||||
|
|
||||||
import { ConfigType } from '../../types/config';
|
import { ConfigType } from '../../types/config';
|
||||||
import { getConfig } from './getConfig';
|
import { getConfig } from './getConfig';
|
||||||
|
|
||||||
export const getFrontendConfig = (name: string): ConfigType => {
|
export const getFrontendConfig = (name: string): ConfigType => {
|
||||||
const config = getConfig(name);
|
const config = getConfig(name);
|
||||||
|
|
||||||
|
Consola.info(`Requested frontend content of configuration '${name}'`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...config,
|
...config,
|
||||||
apps: config.apps.map((app) => ({
|
apps: config.apps.map((app) => ({
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ const fetchCopy = async (configName: string, config: ConfigType | undefined) =>
|
|||||||
throw new Error('config is not defiend');
|
throw new Error('config is not defiend');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const copiedConfig = config;
|
||||||
|
copiedConfig.configProperties.name = configName;
|
||||||
|
|
||||||
const response = await fetch(`/api/configs/${configName}`, {
|
const response = await fetch(`/api/configs/${configName}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
Reference in New Issue
Block a user