import { Switch } from "@radix-ui/react-switch"; import classNames from "classnames"; import { useAppStore } from "../../store/app-store"; import { useProjectStore } from "../../store/project-store"; import { AppState } from "../../types"; import CodePreview from "../preview/CodePreview"; import Spinner from "../core/Spinner"; import KeyboardShortcutBadge from "../core/KeyboardShortcutBadge"; import TipLink from "../messages/TipLink"; import SelectAndEditModeToggleButton from "../select-and-edit/SelectAndEditModeToggleButton"; import { Button } from "../ui/button"; import { Textarea } from "../ui/textarea"; import { useEffect, useRef } from "react"; import HistoryDisplay from "../history/HistoryDisplay"; import Variants from "../variants/Variants"; interface SidebarProps { showSelectAndEditFeature: boolean; doUpdate: (instruction: string) => void; regenerate: () => void; cancelCodeGeneration: () => void; } function Sidebar({ showSelectAndEditFeature, doUpdate, regenerate, cancelCodeGeneration, }: SidebarProps) { const textareaRef = useRef(null); const { appState, updateInstruction, setUpdateInstruction, shouldIncludeResultImage, setShouldIncludeResultImage, } = useAppStore(); const { inputMode, referenceImages, executionConsoles, head, commits } = useProjectStore(); const viewedCode = head && commits[head] ? commits[head].variants[commits[head].selectedVariantIndex].code : ""; const executionConsole = (head && executionConsoles[commits[head].selectedVariantIndex]) || []; // When coding is complete, focus on the update instruction textarea useEffect(() => { if (appState === AppState.CODE_READY && textareaRef.current) { textareaRef.current.focus(); } }, [appState]); return ( <> {/* Show code preview only when coding */} {appState === AppState.CODING && (
{/* Speed disclaimer for video mode */} {inputMode === "video" && (
Code generation from videos can take 3-4 minutes. We do multiple passes to get the best result. Please be patient.
)}
{executionConsole.slice(-1)[0]}
)} {appState === AppState.CODE_READY && (