Skip to content

Commit

Permalink
♻️ refactor: merge plugin setting in the action layer instead of UI
Browse files Browse the repository at this point in the history
  • Loading branch information
YangHanlin committed Apr 27, 2024
1 parent 4d6f850 commit 862d0f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/features/PluginSettings/index.tsx
Expand Up @@ -74,7 +74,7 @@ const PluginSettingsConfig = memo<PluginSettingsConfigProps>(({ schema, id }) =>
maximum={item.maximum}
minimum={item.minimum}
onChange={(value) => {
updatePluginSettings(id, { ...pluginSetting, [item.name]: value });
updatePluginSettings(id, { [item.name]: value });
}}
type={item.type as any}
/>
Expand Down
7 changes: 6 additions & 1 deletion src/store/tool/slices/plugin/action.ts
Expand Up @@ -3,6 +3,7 @@ import useSWR, { SWRResponse } from 'swr';
import { StateCreator } from 'zustand/vanilla';

import { pluginService } from '@/services/plugin';
import { merge } from '@/utils/merge';

import { ToolStore } from '../../store';
import { pluginStoreSelectors } from '../store/selectors';
Expand Down Expand Up @@ -44,7 +45,11 @@ export const createPluginSlice: StateCreator<
await get().refreshPlugins();
},
updatePluginSettings: async (id, settings) => {
await pluginService.updatePluginSettings(id, settings);
const previousSettings = pluginSelectors.getPluginSettingsById(id)(get());

const nextSettings = merge(previousSettings, settings);
await pluginService.updatePluginSettings(id, nextSettings);

await get().refreshPlugins();
},
useCheckPluginsIsInstalled: (plugins) => useSWR(plugins, get().checkPluginsIsInstalled),
Expand Down

0 comments on commit 862d0f6

Please sign in to comment.