Add new config format

This commit is contained in:
Meierschlumpf
2022-12-04 17:36:30 +01:00
parent b2f5149527
commit d5a3b3f3ba
76 changed files with 2461 additions and 1034 deletions

35
src/config/store.ts Normal file
View File

@@ -0,0 +1,35 @@
import create from 'zustand';
import { ConfigType } from '../types/config';
export const useConfigStore = create<UseConfigStoreType>((set, get) => ({
configs: [],
initConfig: (name, config) => {
set((old) => ({
...old,
configs: [...old.configs.filter((x) => x.configProperties?.name !== name), config],
}));
},
// TODO: use callback with current config as input
updateConfig: async (name, updateCallback: (previous: ConfigType) => ConfigType) => {
const { configs } = get();
const currentConfig = configs.find((x) => x.configProperties.name === name);
if (!currentConfig) return;
// TODO: update config on server
const updatedConfig = updateCallback(currentConfig);
set((old) => ({
...old,
configs: [...old.configs.filter((x) => x.configProperties.name !== name), updatedConfig],
}));
},
}));
interface UseConfigStoreType {
configs: ConfigType[];
initConfig: (name: string, config: ConfigType) => void;
updateConfig: (
name: string,
updateCallback: (previous: ConfigType) => ConfigType
) => Promise<void>;
}