From 22b9723362c16140f227f265963466d013e25116 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:45:43 -0400 Subject: [PATCH] Refactor --- webview-ui/src/App.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/webview-ui/src/App.tsx b/webview-ui/src/App.tsx index b93605d..64e284d 100644 --- a/webview-ui/src/App.tsx +++ b/webview-ui/src/App.tsx @@ -20,11 +20,14 @@ const AppContent = () => { const message: ExtensionMessage = e.data switch (message.type) { case "state": - const hasKey = - message.state!.apiConfiguration?.apiKey !== undefined || - message.state!.apiConfiguration?.openRouterApiKey !== undefined || - message.state!.apiConfiguration?.awsAccessKey !== undefined || - message.state!.apiConfiguration?.vertexProjectId !== undefined + let hasKey = false + const config = message.state?.apiConfiguration + if (config) { + const { apiKey, openRouterApiKey, awsAccessKey, vertexProjectId } = config + hasKey = [apiKey, openRouterApiKey, awsAccessKey, vertexProjectId].some((key) => key !== undefined) + } else { + hasKey = false + } setShowWelcome(!hasKey) break case "action": @@ -44,7 +47,6 @@ const AppContent = () => { } break } - // (react-use takes care of not registering the same listener multiple times even if this callback is updated.) }, []) useEvent("message", handleMessage)