From ed2275e243f7e9fdac958d62505f5281b2aca9ab Mon Sep 17 00:00:00 2001 From: Kiet <31864905+Kitenite@users.noreply.github.com> Date: Tue, 1 Oct 2024 13:12:28 -0400 Subject: [PATCH] Instant write-to-code support (#431) * Track new write code actions * Add loading state for writing to code --- app/src/lib/editor/engine/code/index.ts | 3 ++- app/src/routes/editor/TopBar/index.tsx | 28 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/src/lib/editor/engine/code/index.ts b/app/src/lib/editor/engine/code/index.ts index 865b73d3..23bd2e10 100644 --- a/app/src/lib/editor/engine/code/index.ts +++ b/app/src/lib/editor/engine/code/index.ts @@ -48,6 +48,7 @@ export class CodeManager { this.isQueued = true; return; } + this.isExecuting = true; const codeDiffs = await this.generateCodeDiffs(); if (codeDiffs.length === 0) { console.error('No code diffs found.'); @@ -59,7 +60,7 @@ export class CodeManager { webview.send(WebviewChannels.CLEAN_AFTER_WRITE_TO_CODE); }); } - + sendAnalytics('write code'); this.isExecuting = false; if (this.isQueued) { this.isQueued = false; diff --git a/app/src/routes/editor/TopBar/index.tsx b/app/src/routes/editor/TopBar/index.tsx index 4ae3c90c..490c3841 100644 --- a/app/src/routes/editor/TopBar/index.tsx +++ b/app/src/routes/editor/TopBar/index.tsx @@ -2,7 +2,7 @@ import { useEditorEngine } from '@/components/Context'; import { Button } from '@/components/ui/button'; import { HotKeyLabel } from '@/components/ui/hotkeys-label'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; -import { ResetIcon } from '@radix-ui/react-icons'; +import { CheckCircledIcon, ResetIcon, ShadowIcon } from '@radix-ui/react-icons'; import { observer } from 'mobx-react-lite'; import ModeToggle from './ModeToggle'; import OpenCode from './OpenCode'; @@ -53,11 +53,27 @@ const EditorTopBar = observer(() => { ))} -

- {editorEngine.history.length === 0 - ? '' - : `${editorEngine.history.length} change${editorEngine.history.length > 1 ? 's' : ''}`} -

+ {editorEngine.history.length > 0 && ( + + +
+ {editorEngine.code.isExecuting ? ( + + ) : ( + + )} +

{`${editorEngine.history.length} change${editorEngine.history.length > 1 ? 's' : ''}`}

+
+
+ +

+ {editorEngine.code.isExecuting + ? 'Writing code' + : 'Edits written to code'} +

+
+
+ )}