Skip to content

Commit a16f24d

Browse files
committed
Remove hardcoded timeout
1 parent 80e27c2 commit a16f24d

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

src/core/webview/webviewMessageHandler.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,11 +2388,26 @@ export const webviewMessageHandler = async (
23882388

23892389
// Refresh the state to update UI
23902390
await provider.postStateToWebview()
2391+
2392+
// Send success response back to webview
2393+
await provider.postMessageToWebview({
2394+
type: "organizationSwitchResult",
2395+
success: true,
2396+
organizationId: organizationId,
2397+
})
23912398
} catch (error) {
23922399
provider.log(`Organization switch failed: ${error}`)
2393-
vscode.window.showErrorMessage(
2394-
`Failed to switch organization: ${error instanceof Error ? error.message : String(error)}`,
2395-
)
2400+
const errorMessage = error instanceof Error ? error.message : String(error)
2401+
2402+
// Send error response back to webview
2403+
await provider.postMessageToWebview({
2404+
type: "organizationSwitchResult",
2405+
success: false,
2406+
error: errorMessage,
2407+
organizationId: message.organizationId ?? null,
2408+
})
2409+
2410+
vscode.window.showErrorMessage(`Failed to switch organization: ${errorMessage}`)
23962411
}
23972412
break
23982413
}

src/shared/ExtensionMessage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export interface ExtensionMessage {
125125
| "commands"
126126
| "insertTextIntoTextarea"
127127
| "dismissedUpsells"
128+
| "organizationSwitchResult"
128129
text?: string
129130
payload?: any // Add a generic payload for now, can refine later
130131
action?:
@@ -203,6 +204,7 @@ export interface ExtensionMessage {
203204
commands?: Command[]
204205
queuedMessages?: QueuedMessage[]
205206
list?: string[] // For dismissedUpsells
207+
organizationId?: string | null // For organizationSwitchResult
206208
}
207209

208210
export type ExtensionState = Pick<

webview-ui/src/components/cloud/OrganizationSwitcher.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, SelectSe
44
import { type CloudUserInfo, type CloudOrganizationMembership } from "@roo-code/types"
55
import { useAppTranslation } from "@src/i18n/TranslationContext"
66
import { vscode } from "@src/utils/vscode"
7+
import { type ExtensionMessage } from "@roo/ExtensionMessage"
78

89
type OrganizationSwitcherProps = {
910
userInfo: CloudUserInfo
@@ -21,6 +22,28 @@ export const OrganizationSwitcher = ({ userInfo, organizations, onOrganizationCh
2122
setSelectedOrgId(userInfo.organizationId || null)
2223
}, [userInfo.organizationId])
2324

25+
// Listen for organization switch results
26+
useEffect(() => {
27+
const handleMessage = (event: MessageEvent) => {
28+
const message = event.data as ExtensionMessage
29+
if (message.type === "organizationSwitchResult") {
30+
// Reset loading state when we receive the result
31+
setIsLoading(false)
32+
33+
if (message.success) {
34+
// Update selected org based on the result
35+
setSelectedOrgId(message.organizationId ?? null)
36+
} else {
37+
// Revert to the previous organization on error
38+
setSelectedOrgId(userInfo.organizationId || null)
39+
}
40+
}
41+
}
42+
43+
window.addEventListener("message", handleMessage)
44+
return () => window.removeEventListener("message", handleMessage)
45+
}, [userInfo.organizationId])
46+
2447
const handleOrganizationChange = async (value: string) => {
2548
const newOrgId = value === "personal" ? null : value
2649

@@ -44,11 +67,6 @@ export const OrganizationSwitcher = ({ userInfo, organizations, onOrganizationCh
4467
if (onOrganizationChange) {
4568
onOrganizationChange(newOrgId)
4669
}
47-
48-
// Reset loading state after a delay
49-
setTimeout(() => {
50-
setIsLoading(false)
51-
}, 1000)
5270
}
5371

5472
// If user has no organizations, don't show the switcher

0 commit comments

Comments
 (0)