import { useCallback, useEffect, useRef, useState } from "react"; import styled, { keyframes } from "styled-components"; import { appear, buttonColor, defaultBorderRadius, MainContainerWithBorder, MainTextInput, secondaryDark, vscBackground, GradientBorder, } from "."; import { RangeInFile, FileEdit } from "../../../src/client"; import CodeBlock from "./CodeBlock"; import SubContainer from "./SubContainer"; import { ChevronDown, ChevronRight, Backward, } from "@styled-icons/heroicons-outline"; import { HistoryNode } from "../../../schema/HistoryNode"; import ReactMarkdown from "react-markdown"; import ContinueButton from "./ContinueButton"; interface StepContainerProps { historyNode: HistoryNode; onReverse: () => void; inFuture: boolean; onRefinement: (input: string) => void; onUserInput: (input: string) => void; } const MainDiv = styled.div<{ stepDepth: number; inFuture: boolean }>` opacity: ${(props) => (props.inFuture ? 0.3 : 1)}; animation: ${appear} 0.3s ease-in-out; /* padding-left: ${(props) => props.stepDepth * 20}px; */ overflow: hidden; `; const StepContainerDiv = styled.div<{ open: boolean }>` background-color: ${(props) => (props.open ? vscBackground : secondaryDark)}; border-radius: ${defaultBorderRadius}; padding: 8px; `; const HeaderDiv = styled.div` display: grid; grid-template-columns: 1fr auto; align-items: center; `; const HeaderButton = styled.button` background-color: transparent; border: 1px solid white; border-radius: ${defaultBorderRadius}; padding: 2px; cursor: pointer; color: white; &:hover { background-color: white; color: black; } `; const OnHoverDiv = styled.div` text-align: center; padding: 10px; animation: ${appear} 0.3s ease-in-out; `; const NaturalLanguageInput = styled(MainTextInput)` width: 80%; `; function StepContainer(props: StepContainerProps) { const [open, setOpen] = useState(false); const [isHovered, setIsHovered] = useState(false); const naturalLanguageInputRef = useRef(null); useEffect(() => { if (isHovered) { naturalLanguageInputRef.current?.focus(); } }, [isHovered]); const onTextInput = useCallback(() => { if (naturalLanguageInputRef.current) { props.onRefinement(naturalLanguageInputRef.current.value); naturalLanguageInputRef.current.value = ""; } }, [naturalLanguageInputRef]); return ( { setIsHovered(true); }} onMouseLeave={() => { setIsHovered(false); }} hidden={props.historyNode.step.hide as any} > setOpen((prev) => !prev)} >

{open ? ( ) : ( )} {props.historyNode.step.name as any}:

{ e.stopPropagation(); props.onReverse(); }} >
{props.historyNode.step.description as any} {props.historyNode.step.name === "Waiting for user input" && ( { if (e.key === "Enter") { props.onUserInput(e.currentTarget.value); } }} type="text" onSubmit={(ev) => { props.onUserInput(ev.currentTarget.value); }} /> )} {props.historyNode.step.name === "Waiting for user confirmation" && ( <> { props.onUserInput("ok"); e.preventDefault(); e.stopPropagation(); }} type="button" value="Confirm" /> )} {open && ( <> {/* {props.historyNode.observation && ( Error Here )} */} {/* {props.iterationContext.suggestedChanges.map((sc) => { return ( {sc.filepath} {sc.replacement} ); })} */} )}
); } export default StepContainer;