From 0298e7af7fef0e6bf93f0c0528de672eaea655df Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:42:20 -0400 Subject: [PATCH] Add Kodu announcement --- src/providers/ClaudeDevProvider.ts | 3 +- src/shared/ExtensionMessage.ts | 1 + src/shared/WebviewMessage.ts | 2 +- webview-ui/src/App.tsx | 11 ++++- webview-ui/src/components/Announcement.tsx | 39 ++++++++++----- webview-ui/src/components/ApiOptions.tsx | 55 +++++++++------------- webview-ui/src/components/ChatView.tsx | 11 ++++- webview-ui/src/components/WelcomeView.tsx | 44 +++++++++++++---- 8 files changed, 107 insertions(+), 59 deletions(-) diff --git a/src/providers/ClaudeDevProvider.ts b/src/providers/ClaudeDevProvider.ts index 7971287..e238534 100644 --- a/src/providers/ClaudeDevProvider.ts +++ b/src/providers/ClaudeDevProvider.ts @@ -320,7 +320,7 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider { await this.clearTask() await this.postStateToWebview() break - case "didShowAnnouncement": + case "didCloseAnnouncement": await this.updateGlobalState("lastShownAnnouncementId", this.latestAnnouncementId) await this.postStateToWebview() break @@ -377,6 +377,7 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider { await this.updateGlobalState("koduEmail", email) await this.updateGlobalState("apiProvider", "kodu") await this.postStateToWebview() + await this.postMessageToWebview({ type: "action", action: "koduAuthenticated" }) this.claudeDev?.updateApi({ apiProvider: "kodu", koduApiKey: apiKey }) } diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index 1f7e11e..1203d62 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -12,6 +12,7 @@ export interface ExtensionMessage { | "settingsButtonTapped" | "historyButtonTapped" | "didBecomeVisible" + | "koduAuthenticated" | "koduCreditsFetched" state?: ExtensionState images?: string[] diff --git a/src/shared/WebviewMessage.ts b/src/shared/WebviewMessage.ts index e2a258e..f858817 100644 --- a/src/shared/WebviewMessage.ts +++ b/src/shared/WebviewMessage.ts @@ -9,7 +9,7 @@ export interface WebviewMessage { | "newTask" | "askResponse" | "clearTask" - | "didShowAnnouncement" + | "didCloseAnnouncement" | "selectImages" | "exportCurrentTask" | "showTaskWithId" diff --git a/webview-ui/src/App.tsx b/webview-ui/src/App.tsx index c7f99fe..3b7b53f 100644 --- a/webview-ui/src/App.tsx +++ b/webview-ui/src/App.tsx @@ -59,7 +59,6 @@ const App: React.FC = () => { // don't update showAnnouncement to false if shouldShowAnnouncement is false if (message.state!.shouldShowAnnouncement) { setShowAnnouncement(true) - vscode.postMessage({ type: "didShowAnnouncement" }) } setDidHydrateState(true) break @@ -77,6 +76,10 @@ const App: React.FC = () => { setShowSettings(false) setShowHistory(false) break + case "koduAuthenticated": + setShowSettings(true) + setShowHistory(false) + break } break } @@ -127,7 +130,11 @@ const App: React.FC = () => { showAnnouncement={showAnnouncement} selectedModelSupportsImages={selectedModelInfo.supportsImages} selectedModelSupportsPromptCache={selectedModelInfo.supportsPromptCache} - hideAnnouncement={() => setShowAnnouncement(false)} + hideAnnouncement={() => { + vscode.postMessage({ type: "didCloseAnnouncement" }) + setShowAnnouncement(false) + }} + apiConfiguration={apiConfiguration} /> > )} diff --git a/webview-ui/src/components/Announcement.tsx b/webview-ui/src/components/Announcement.tsx index 4629629..92719d9 100644 --- a/webview-ui/src/components/Announcement.tsx +++ b/webview-ui/src/components/Announcement.tsx @@ -1,13 +1,16 @@ import { VSCodeButton, VSCodeLink } from "@vscode/webview-ui-toolkit/react" +import { vscode } from "../utils/vscode" +import { ApiConfiguration } from "../../../src/shared/api" interface AnnouncementProps { version: string hideAnnouncement: () => void + apiConfiguration?: ApiConfiguration } /* You must update the latestAnnouncementId in ClaudeDevProvider for new announcements to show to users. This new id will be compared with whats in state for the 'last announcement shown', and if it's different then the announcement will render. As soon as an announcement is shown, the id will be updated in state. This ensures that announcements are not shown more than once, even if the user doesn't close it themselves. */ -const Announcement = ({ version, hideAnnouncement }: AnnouncementProps) => { +const Announcement = ({ version, hideAnnouncement, apiConfiguration }: AnnouncementProps) => { return (
Follow me for more updates!{" "}
diff --git a/webview-ui/src/components/ApiOptions.tsx b/webview-ui/src/components/ApiOptions.tsx
index 9470872..48a8511 100644
--- a/webview-ui/src/components/ApiOptions.tsx
+++ b/webview-ui/src/components/ApiOptions.tsx
@@ -165,9 +165,9 @@ const ApiOptions: React.FC
- Kodu is recommended for its high rate limits and access to the latest features like
- prompt caching.
-
- This will open your browser to sign in to Kodu. You will be redirected back to the
- extension after signing in.
-
+ Kodu is recommended for its high rate limits and access to the latest features like prompt
+ caching.
+
diff --git a/webview-ui/src/components/WelcomeView.tsx b/webview-ui/src/components/WelcomeView.tsx
index 2b91f2e..9d8f796 100644
--- a/webview-ui/src/components/WelcomeView.tsx
+++ b/webview-ui/src/components/WelcomeView.tsx
@@ -31,23 +31,51 @@ const WelcomeView: React.FCWhat can I do for you?