diff --git a/src/providers/SidebarProvider.ts b/src/providers/SidebarProvider.ts index 71e7c66..6955906 100644 --- a/src/providers/SidebarProvider.ts +++ b/src/providers/SidebarProvider.ts @@ -137,7 +137,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider { switch (message.type) { case "webviewDidLaunch": await this.updateGlobalState("didOpenOnce", true) - await this.postWebviewState() + await this.postStateToWebview() break case "text": // Code that should run in response to the hello message command @@ -150,7 +150,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider { break case "apiKey": await this.storeSecret("apiKey", message.text!) - await this.postWebviewState() + await this.postStateToWebview() break case "maxRequestsPerTask": let result: number | undefined = undefined @@ -161,7 +161,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider { } } await this.updateGlobalState("maxRequestsPerTask", result) - await this.postWebviewState() + await this.postStateToWebview() break // Add more switch case statements here as more webview message commands // are created within the webview context (i.e. inside media/main.js) @@ -169,15 +169,15 @@ export class SidebarProvider implements vscode.WebviewViewProvider { }) } - private async postWebviewState() { + private async postStateToWebview() { const [didOpenOnce, apiKey, maxRequestsPerTask] = await Promise.all([ this.getGlobalState("didOpenOnce") as Promise, this.getSecret("apiKey") as Promise, this.getGlobalState("maxRequestsPerTask") as Promise, ]) this.postMessageToWebview({ - type: "webviewState", - webviewState: { didOpenOnce: !!didOpenOnce, apiKey: apiKey, maxRequestsPerTask: maxRequestsPerTask }, + type: "state", + state: { didOpenOnce: !!didOpenOnce, apiKey: apiKey, maxRequestsPerTask: maxRequestsPerTask }, }) } diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index 6a0ab59..99347af 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -2,8 +2,8 @@ // webview will hold state export interface ExtensionMessage { - type: "text" | "action" | "webviewState" + type: "text" | "action" | "state" text?: string action?: "plusButtonTapped" | "settingsButtonTapped" - webviewState?: { didOpenOnce: boolean, apiKey?: string, maxRequestsPerTask?: number } + state?: { didOpenOnce: boolean, apiKey?: string, maxRequestsPerTask?: number } } \ No newline at end of file diff --git a/webview-ui/src/App.tsx b/webview-ui/src/App.tsx index 18c5cb0..3df98e3 100644 --- a/webview-ui/src/App.tsx +++ b/webview-ui/src/App.tsx @@ -27,13 +27,13 @@ const App: React.FC = () => { const message: ExtensionMessage = e.data // switch message.type switch (message.type) { - case "webviewState": - const shouldShowWelcome = !message.webviewState!.didOpenOnce || !message.webviewState!.apiKey + case "state": + const shouldShowWelcome = !message.state!.didOpenOnce || !message.state!.apiKey setShowWelcome(shouldShowWelcome) - setApiKey(message.webviewState!.apiKey || "") + setApiKey(message.state!.apiKey || "") setMaxRequestsPerTask( - message.webviewState!.maxRequestsPerTask !== undefined - ? message.webviewState!.maxRequestsPerTask.toString() + message.state!.maxRequestsPerTask !== undefined + ? message.state!.maxRequestsPerTask.toString() : "" ) break