🐛 Fix deprecated zustand dependencies

This commit is contained in:
Meier Lukas
2023-08-09 21:41:57 +02:00
parent d9eec612d8
commit db8d88affc
5 changed files with 94 additions and 130 deletions

View File

@@ -360,54 +360,6 @@
} }
} }
} }
},
{
"id": "135b7adf-0616-481f-991e-a9035d66b924",
"type": "torrents-status",
"properties": {
"displayCompletedTorrents": true,
"displayStaleTorrents": true,
"labelFilterIsWhitelist": true,
"labelFilter": []
},
"area": {
"type": "wrapper",
"properties": {
"id": "default"
}
},
"shape": {
"sm": {
"location": {
"x": 0,
"y": 0
},
"size": {
"width": 2,
"height": 2
}
},
"md": {
"location": {
"x": 0,
"y": 0
},
"size": {
"width": 2,
"height": 2
}
},
"lg": {
"location": {
"x": 0,
"y": 0
},
"size": {
"width": 2,
"height": 2
}
}
}
} }
], ],
"settings": { "settings": {

View File

@@ -1,11 +1,14 @@
import { create } from 'zustand'; import { createWithEqualityFn } from 'zustand/traditional';
interface EditModeState { interface EditModeState {
enabled: boolean; enabled: boolean;
toggleEditMode: () => void; toggleEditMode: () => void;
} }
export const useEditModeStore = create<EditModeState>((set) => ({ export const useEditModeStore = createWithEqualityFn<EditModeState>(
enabled: false, (set) => ({
toggleEditMode: () => set((state) => ({ enabled: !state.enabled })), enabled: false,
})); toggleEditMode: () => set((state) => ({ enabled: !state.enabled })),
}),
Object.is
);

View File

@@ -1,14 +1,17 @@
import { create } from 'zustand'; import { createWithEqualityFn } from 'zustand/traditional';
import { useConfigContext } from '../../../../config/provider'; import { useConfigContext } from '../../../../config/provider';
import { GridstackBreakpoints } from '../../../../constants/gridstack-breakpoints'; import { GridstackBreakpoints } from '../../../../constants/gridstack-breakpoints';
export const useGridstackStore = create<GridstackStoreType>((set, get) => ({ export const useGridstackStore = createWithEqualityFn<GridstackStoreType>(
mainAreaWidth: null, (set, get) => ({
currentShapeSize: null, mainAreaWidth: null,
setMainAreaWidth: (w: number) => currentShapeSize: null,
set((v) => ({ ...v, mainAreaWidth: w, currentShapeSize: getCurrentShapeSize(w) })), setMainAreaWidth: (w: number) =>
})); set((v) => ({ ...v, mainAreaWidth: w, currentShapeSize: getCurrentShapeSize(w) })),
}),
Object.is
);
interface GridstackStoreType { interface GridstackStoreType {
mainAreaWidth: null | number; mainAreaWidth: null | number;

View File

@@ -1,74 +1,77 @@
import { create } from 'zustand'; import { createWithEqualityFn } from 'zustand/traditional';
import { trcpProxyClient } from '~/utils/api'; import { trcpProxyClient } from '~/utils/api';
import { ConfigType } from '../types/config'; import { ConfigType } from '../types/config';
export const useConfigStore = create<UseConfigStoreType>((set, get) => ({ export const useConfigStore = createWithEqualityFn<UseConfigStoreType>(
configs: [], (set, get) => ({
initConfig: (name, config, increaseVersion) => { configs: [],
set((old) => ({ initConfig: (name, config, increaseVersion) => {
...old, set((old) => ({
configs: [ ...old,
...old.configs.filter((x) => x.value.configProperties?.name !== name), configs: [
{ increaseVersion, value: config }, ...old.configs.filter((x) => x.value.configProperties?.name !== name),
], { increaseVersion, value: config },
})); ],
}, }));
addConfig: async (name: string, config: ConfigType) => { },
set((old) => ({ addConfig: async (name: string, config: ConfigType) => {
...old, set((old) => ({
configs: [ ...old,
...old.configs.filter((x) => x.value.configProperties.name !== name), configs: [
{ value: config, increaseVersion: () => {} }, ...old.configs.filter((x) => x.value.configProperties.name !== name),
], { value: config, increaseVersion: () => {} },
})); ],
}, }));
removeConfig: (name: string) => { },
set((old) => ({ removeConfig: (name: string) => {
...old, set((old) => ({
configs: old.configs.filter((x) => x.value.configProperties.name !== name), ...old,
})); configs: old.configs.filter((x) => x.value.configProperties.name !== name),
}, }));
updateConfig: async ( },
name, updateConfig: async (
updateCallback: (previous: ConfigType) => ConfigType, name,
shouldRegenerateGridstack = false, updateCallback: (previous: ConfigType) => ConfigType,
shouldSaveConfigToFileSystem = false shouldRegenerateGridstack = false,
) => { shouldSaveConfigToFileSystem = false
const { configs } = get(); ) => {
const currentConfig = configs.find((x) => x.value.configProperties.name === name); const { configs } = get();
if (!currentConfig) { const currentConfig = configs.find((x) => x.value.configProperties.name === name);
return; 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)); // copies the value of currentConfig and creates a non reference object named previousConfig
const previousConfig: ConfigType = JSON.parse(JSON.stringify(currentConfig.value));
const updatedConfig = updateCallback(currentConfig.value); const updatedConfig = updateCallback(currentConfig.value);
set((old) => ({ set((old) => ({
...old, ...old,
configs: [ configs: [
...old.configs.filter((x) => x.value.configProperties.name !== name), ...old.configs.filter((x) => x.value.configProperties.name !== name),
{ value: updatedConfig, increaseVersion: currentConfig.increaseVersion }, { value: updatedConfig, increaseVersion: currentConfig.increaseVersion },
], ],
})); }));
if ( if (
(typeof shouldRegenerateGridstack === 'boolean' && shouldRegenerateGridstack) || (typeof shouldRegenerateGridstack === 'boolean' && shouldRegenerateGridstack) ||
(typeof shouldRegenerateGridstack === 'function' && (typeof shouldRegenerateGridstack === 'function' &&
shouldRegenerateGridstack(previousConfig, updatedConfig)) shouldRegenerateGridstack(previousConfig, updatedConfig))
) { ) {
currentConfig.increaseVersion(); currentConfig.increaseVersion();
} }
if (shouldSaveConfigToFileSystem) { if (shouldSaveConfigToFileSystem) {
trcpProxyClient.config.save.mutate({ trcpProxyClient.config.save.mutate({
name, name,
config: updatedConfig, config: updatedConfig,
}); });
} }
}, },
})); }),
Object.is
);
interface UseConfigStoreType { interface UseConfigStoreType {
configs: { increaseVersion: () => void; value: ConfigType }[]; configs: { increaseVersion: () => void; value: ConfigType }[];

View File

@@ -1,4 +1,4 @@
import { create } from 'zustand'; import { createWithEqualityFn } from 'zustand/traditional';
import { ServerSidePackageAttributesType } from '../../server/getPackageVersion'; import { ServerSidePackageAttributesType } from '../../server/getPackageVersion';
@@ -7,9 +7,12 @@ interface PackageAttributesState {
setInitialPackageAttributes: (attributes: ServerSidePackageAttributesType) => void; setInitialPackageAttributes: (attributes: ServerSidePackageAttributesType) => void;
} }
export const usePackageAttributesStore = create<PackageAttributesState>((set) => ({ export const usePackageAttributesStore = createWithEqualityFn<PackageAttributesState>(
attributes: { packageVersion: undefined, environment: 'test', dependencies: {} }, (set) => ({
setInitialPackageAttributes(attributes) { attributes: { packageVersion: undefined, environment: 'test', dependencies: {} },
set((state) => ({ ...state, attributes })); setInitialPackageAttributes(attributes) {
}, set((state) => ({ ...state, attributes }));
})); },
}),
Object.is
);