From 9eef4988e7f32a8523c820f2abcc181f4d9a5728 Mon Sep 17 00:00:00 2001 From: ajnart Date: Tue, 24 May 2022 22:55:47 +0200 Subject: [PATCH] :sparkles: Add a way to save a config and delete it --- src/components/Config/ConfigChanger.tsx | 2 +- src/components/Config/SaveConfig.tsx | 90 +++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/src/components/Config/ConfigChanger.tsx b/src/components/Config/ConfigChanger.tsx index 5b8836803..8d4be4db8 100644 --- a/src/components/Config/ConfigChanger.tsx +++ b/src/components/Config/ConfigChanger.tsx @@ -9,7 +9,7 @@ export default function ConfigChanger() { useEffect(() => { getConfigs().then((configs) => setConfigList(configs)); // setConfig(initialConfig); - }, [config]); + }, [config.name]); // If configlist is empty, return a loading indicator if (configList.length === 0) { return ( diff --git a/src/components/Config/SaveConfig.tsx b/src/components/Config/SaveConfig.tsx index cfaf196d4..a0b7997e7 100644 --- a/src/components/Config/SaveConfig.tsx +++ b/src/components/Config/SaveConfig.tsx @@ -1,18 +1,96 @@ -import { Button } from '@mantine/core'; +import { Button, Group, Modal, TextInput } from '@mantine/core'; +import { useForm } from '@mantine/form'; +import { showNotification } from '@mantine/notifications'; +import axios from 'axios'; import fileDownload from 'js-file-download'; -import { Download } from 'tabler-icons-react'; +import { useState } from 'react'; +import { Check, Download, Plus, Trash, X } from 'tabler-icons-react'; import { useConfig } from '../../tools/state'; export default function SaveConfigComponent(props: any) { - const { config } = useConfig(); + const [opened, setOpened] = useState(false); + const { config, setConfig } = useConfig(); + const form = useForm({ + initialValues: { + configName: config.name, + }, + }); function onClick(e: any) { if (config) { fileDownload(JSON.stringify(config, null, '\t'), `${config.name}.json`); } } return ( - + + setOpened(false)} + title="Choose the name of your new config" + > +
{ + setConfig({ ...config, name: values.configName }); + setOpened(false); + showNotification({ + title: 'Config saved', + icon: , + color: 'green', + autoClose: 1500, + radius: 'md', + message: `Config saved as ${values.configName}`, + }); + })} + > + + + + + +
+ + + +
); }