fix(openclaw): update button state and toast message after switch

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).
This commit is contained in:
Jason
2026-02-05 22:58:05 +08:00
parent 46ab15f9f6
commit c431a86064
2 changed files with 15 additions and 7 deletions

View File

@@ -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,

View File

@@ -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();