From 2f1745a0b51ca53403000f6a2fb339c27318556a Mon Sep 17 00:00:00 2001 From: clean99 Date: Tue, 21 Nov 2023 15:54:01 +0800 Subject: [PATCH] feat: refactor app status type --- frontend/src/App.tsx | 26 +++++++++++++------------- frontend/src/types.ts | 6 ++++++ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index c2ec3fe..bb71064 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -17,7 +17,7 @@ import { Textarea } from "@/components/ui/textarea"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "./components/ui/tabs"; import CodeMirror from "./components/CodeMirror"; import SettingsDialog from "./components/SettingsDialog"; -import { Settings } from "./types"; +import { AppStatus, Settings } from "./types"; import { IS_RUNNING_ON_CLOUD } from "./config"; import { PicoBadge } from "./components/PicoBadge"; import { OnboardingNote } from "./components/OnboardingNote"; @@ -26,8 +26,8 @@ import { UrlInputSection } from "./components/UrlInputSection"; import TermsOfServiceDialog from "./components/TermsOfServiceDialog"; function App() { - const [appState, setAppState] = useState<"INITIAL" | "CODING" | "CODE_READY">( - "INITIAL" + const [appState, setAppState] = useState( + AppStatus.INITIAL ); const [generatedCode, setGeneratedCode] = useState(""); const [referenceImages, setReferenceImages] = useState([]); @@ -62,7 +62,7 @@ function App() { }; const reset = () => { - setAppState("INITIAL"); + setAppState(AppStatus.INITIAL); setGeneratedCode(""); setReferenceImages([]); setExecutionConsole([]); @@ -71,7 +71,7 @@ function App() { function doGenerateCode(params: CodeGenerationParams) { setExecutionConsole([]); - setAppState("CODING"); + setAppState(AppStatus.CODING); // Merge settings with params const updatedParams = { ...params, ...settings }; @@ -81,7 +81,7 @@ function App() { (token) => setGeneratedCode((prev) => prev + token), (code) => setGeneratedCode(code), (line) => setExecutionConsole((prev) => [...prev, line]), - () => setAppState("CODE_READY") + () => setAppState(AppStatus.CODE_READY) ); } @@ -122,7 +122,7 @@ function App() {

Screenshot to Code

- {appState === "INITIAL" && ( + {appState === AppStatus.INITIAL && (

Drag & drop a screenshot to get started.

@@ -130,10 +130,10 @@ function App() { {IS_RUNNING_ON_CLOUD && !settings.openAiApiKey && } - {(appState === "CODING" || appState === "CODE_READY") && ( + {(appState === AppStatus.CODING || appState === AppStatus.CODE_READY) && ( <> {/* Show code preview only when coding */} - {appState === "CODING" && ( + {appState === AppStatus.CODING && (
@@ -143,7 +143,7 @@ function App() {
)} - {appState === "CODE_READY" && ( + {appState === AppStatus.CODE_READY && (