Skip to content

Commit

Permalink
🐛 fix: 修正删除插件时错误开启的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Sep 9, 2023
1 parent 27f8d6d commit 0e35c18
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/features/AgentSetting/AgentPlugin/LocalPluginItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const MarketList = memo<{ id: string }>(({ id }) => {
mode={'edit'}
onDelete={() => {
deleteCustomPlugin(id);
toggleAgentPlugin(id);
toggleAgentPlugin(id, false);
}}
onOpenChange={setModal}
onSave={(value) => {
Expand Down
6 changes: 3 additions & 3 deletions src/features/AgentSetting/store/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface Action {

setAgentMeta: (meta: Partial<MetaData>) => void;
streamUpdateMeta: (key: keyof MetaData) => any;
toggleAgentPlugin: (pluginId: string) => void;
toggleAgentPlugin: (pluginId: string, state?: boolean) => void;
/**
* 更新加载状态
* @param key - SessionLoadingState 的键
Expand Down Expand Up @@ -198,8 +198,8 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
};
},

toggleAgentPlugin: (id) => {
get().dispatchConfig({ pluginId: id, type: 'togglePlugin' });
toggleAgentPlugin: (id, state) => {
get().dispatchConfig({ pluginId: id, state, type: 'togglePlugin' });
},

updateLoadingState: (key, value) => {
Expand Down
23 changes: 17 additions & 6 deletions src/features/AgentSetting/store/reducers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { merge } from '@/utils/merge';

export type ConfigDispatch =
| { config: Partial<any>; type: 'update' }
| { pluginId: string; type: 'togglePlugin' }
| { pluginId: string; state?: boolean; type: 'togglePlugin' }
| { type: 'reset' };

export const configReducer = (state: LobeAgentConfig, payload: ConfigDispatch): LobeAgentConfig => {
Expand All @@ -19,15 +19,26 @@ export const configReducer = (state: LobeAgentConfig, payload: ConfigDispatch):

case 'togglePlugin': {
return produce(state, (config) => {
const { pluginId: id } = payload;
const { pluginId: id, state } = payload;
if (config.plugins === undefined) {
config.plugins = [id];
} else {
config.plugins = [];
}

if (typeof state === 'undefined') {
if (config.plugins.includes(id)) {
config.plugins.splice(config.plugins.indexOf(id), 1);
} else {
config.plugins.push(id);

return;
}

config.plugins.push(id);
return;
}

if (!state) {
config.plugins = config.plugins.filter((pluginId) => pluginId !== id);
} else {
config.plugins.push(id);
}
});
}
Expand Down

0 comments on commit 0e35c18

Please sign in to comment.