Fix cookie in Upload form and fix download name

This commit is contained in:
Aj - Thomas
2022-05-12 22:11:28 +02:00
parent 98e4da5a3b
commit 84b7d4bbdc
2 changed files with 10 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import { DropzoneStatus, FullScreenDropzone } from '@mantine/dropzone';
import { showNotification } from '@mantine/notifications'; import { showNotification } from '@mantine/notifications';
import { useRef } from 'react'; import { useRef } from 'react';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { setCookies } from 'cookies-next';
import { useConfig } from '../../tools/state'; import { useConfig } from '../../tools/state';
import { Config } from '../../tools/types'; import { Config } from '../../tools/types';
@@ -69,15 +70,21 @@ export default function LoadConfigComponent(props: any) {
}); });
return; return;
} }
const newConfig: Config = JSON.parse(e);
showNotification({ showNotification({
autoClose: 5000, autoClose: 5000,
radius: 'md', radius: 'md',
title: <Text>Config loaded successfully</Text>, title: (
<Text>
Config <b>{newConfig.name}</b> loaded successfully
</Text>
),
color: 'green', color: 'green',
icon: <Check />, icon: <Check />,
message: undefined, message: undefined,
}); });
setConfig(JSON.parse(e)); setCookies('config-name', newConfig.name, { maxAge: 60 * 60 * 24 * 30 });
setConfig(newConfig);
}); });
}} }}
accept={['application/json']} accept={['application/json']}

View File

@@ -7,7 +7,7 @@ export default function SaveConfigComponent(props: any) {
const { config } = useConfig(); const { config } = useConfig();
function onClick(e: any) { function onClick(e: any) {
if (config) { if (config) {
fileDownload(JSON.stringify(config, null, '\t'), 'config.json'); fileDownload(JSON.stringify(config, null, '\t'), `${config.name}.json`);
} }
} }
return ( return (