🐛 Fix moving between wrappers not working

This commit is contained in:
Meierschlumpf
2022-12-21 20:13:31 +01:00
parent 9977a384e5
commit 8e9f9d23b3
2 changed files with 87 additions and 46 deletions

View File

@@ -20,6 +20,8 @@ export const useConfigStore = create<UseConfigStoreType>((set, get) => ({
const { configs } = get();
const currentConfig = configs.find((x) => x.value.configProperties.name === name);
if (!currentConfig) return;
// copies the value of currentConfig and creates a non reference object named previousConfig
const previousConfig: ConfigType = JSON.parse(JSON.stringify(currentConfig.value));
// TODO: update config on server
const updatedConfig = updateCallback(currentConfig.value);
@@ -31,7 +33,11 @@ export const useConfigStore = create<UseConfigStoreType>((set, get) => ({
],
}));
if (shouldRegenerateGridstack) {
if (
(typeof shouldRegenerateGridstack === 'boolean' && shouldRegenerateGridstack) ||
(typeof shouldRegenerateGridstack === 'function' &&
shouldRegenerateGridstack(previousConfig, updatedConfig))
) {
currentConfig.increaseVersion();
}
},
@@ -43,6 +49,8 @@ interface UseConfigStoreType {
updateConfig: (
name: string,
updateCallback: (previous: ConfigType) => ConfigType,
shouldRegenerateGridstack?: boolean
shouldRegenerateGridstace?:
| boolean
| ((previousConfig: ConfigType, currentConfig: ConfigType) => boolean)
) => Promise<void>;
}