From c431a860640e5f268cc3a1204b4f4920c645d358 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 5 Feb 2026 22:58:05 +0800 Subject: [PATCH] fix(openclaw): update button state and toast message after switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add cache invalidation for openclawLiveProviderIds in useSwitchProviderMutation to ensure button state updates correctly after adding/removing providers. Also fix toast message to show "已添加到配置" for OpenClaw (same as OpenCode). --- src/hooks/useProviderActions.ts | 16 +++++++++------- src/lib/query/mutations.ts | 6 ++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/hooks/useProviderActions.ts b/src/hooks/useProviderActions.ts index ede55f8a2..daf4229b4 100644 --- a/src/hooks/useProviderActions.ts +++ b/src/hooks/useProviderActions.ts @@ -104,13 +104,15 @@ export function useProviderActions(activeApp: AppId) { ); } else { // 普通供应商:显示切换成功 - // OpenCode: show "added to config" message instead of "switched" - const messageKey = - activeApp === "opencode" - ? "notifications.addToConfigSuccess" - : "notifications.switchSuccess"; - const defaultMessage = - activeApp === "opencode" ? "已添加到配置" : "切换成功!"; + // OpenCode/OpenClaw: show "added to config" message instead of "switched" + const isMultiProviderApp = + activeApp === "opencode" || activeApp === "openclaw"; + const messageKey = isMultiProviderApp + ? "notifications.addToConfigSuccess" + : "notifications.switchSuccess"; + const defaultMessage = isMultiProviderApp + ? "已添加到配置" + : "切换成功!"; toast.success(t(messageKey, { defaultValue: defaultMessage }), { closeButton: true, diff --git a/src/lib/query/mutations.ts b/src/lib/query/mutations.ts index a05ca8d49..c5a263deb 100644 --- a/src/lib/query/mutations.ts +++ b/src/lib/query/mutations.ts @@ -174,6 +174,7 @@ export const useSwitchProviderMutation = (appId: AppId) => { onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: ["providers", appId] }); + // OpenCode/OpenClaw: also invalidate live provider IDs cache to update button state if (appId === "opencode") { await queryClient.invalidateQueries({ queryKey: ["opencodeLiveProviderIds"], @@ -182,6 +183,11 @@ export const useSwitchProviderMutation = (appId: AppId) => { queryKey: ["omo", "current-provider-id"], }); } + if (appId === "openclaw") { + await queryClient.invalidateQueries({ + queryKey: ["openclawLiveProviderIds"], + }); + } try { await providersApi.updateTrayMenu();