diff options
Diffstat (limited to 'extension/react-app/src/tabs')
| -rw-r--r-- | extension/react-app/src/tabs/chat/MessageDiv.tsx | 1 | ||||
| -rw-r--r-- | extension/react-app/src/tabs/gui.tsx | 74 | 
2 files changed, 59 insertions, 16 deletions
| diff --git a/extension/react-app/src/tabs/chat/MessageDiv.tsx b/extension/react-app/src/tabs/chat/MessageDiv.tsx index ad81f5e9..1d7bb5f5 100644 --- a/extension/react-app/src/tabs/chat/MessageDiv.tsx +++ b/extension/react-app/src/tabs/chat/MessageDiv.tsx @@ -21,7 +21,6 @@ const Container = styled.div`    width: fit-content;    max-width: 75%;    overflow-y: scroll; -  scrollbar-gutter: stable both-edges;    word-wrap: break-word;    -ms-word-wrap: break-word;    height: fit-content; diff --git a/extension/react-app/src/tabs/gui.tsx b/extension/react-app/src/tabs/gui.tsx index 7dd30acb..c66172a9 100644 --- a/extension/react-app/src/tabs/gui.tsx +++ b/extension/react-app/src/tabs/gui.tsx @@ -1,25 +1,21 @@  import styled from "styled-components";  import { -  Button,    defaultBorderRadius,    vscBackground, -  MainTextInput,    Loader, +  MainTextInput,  } from "../components";  import ContinueButton from "../components/ContinueButton";  import { useCallback, useEffect, useRef, useState } from "react";  import { History } from "../../../schema/History";  import { HistoryNode } from "../../../schema/HistoryNode";  import StepContainer from "../components/StepContainer"; -import { useSelector } from "react-redux"; -import { RootStore } from "../redux/store"; -import useContinueWebsocket from "../hooks/useWebsocket";  import useContinueGUIProtocol from "../hooks/useWebsocket";  let TopGUIDiv = styled.div`    display: grid;    grid-template-columns: 1fr; -  overflow: scroll; +  background-color: ${vscBackground};  `;  let UserInputQueueItem = styled.div` @@ -156,8 +152,20 @@ function GUI(props: GUIProps) {    //   current_index: 0,    // } as any); +  const topGuiDivRef = useRef<HTMLDivElement>(null);    const client = useContinueGUIProtocol(); +  const scrollToBottom = useCallback(() => { +    if (topGuiDivRef.current) { +      setTimeout(() => { +        window.scrollTo({ +          top: window.outerHeight, +          behavior: "smooth", +        }); +      }, 100); +    } +  }, [topGuiDivRef.current]); +    useEffect(() => {      console.log("CLIENT ON STATE UPDATE: ", client, client?.onStateUpdate);      client?.onStateUpdate((state) => { @@ -165,9 +173,15 @@ function GUI(props: GUIProps) {        setWaitingForSteps(state.active);        setHistory(state.history);        setUserInputQueue(state.user_input_queue); + +      scrollToBottom();      });    }, [client]); +  useEffect(() => { +    scrollToBottom(); +  }, [waitingForSteps]); +    const mainTextInputRef = useRef<HTMLTextAreaElement>(null);    useEffect(() => { @@ -189,16 +203,33 @@ function GUI(props: GUIProps) {      if (mainTextInputRef.current) {        if (!client) return;        let input = mainTextInputRef.current.value; -      if (input.trim() === "") return; -      setWaitingForSteps(true); -      client.sendMainInput(input); -      setUserInputQueue((queue) => { -        return [...queue, input]; -      }); -      mainTextInputRef.current.value = ""; -      mainTextInputRef.current.style.height = ""; +      if ( +        history && +        history.timeline[history.current_index].step.name === +          "Waiting for user input" +      ) { +        if (input.trim() === "") return; +        onStepUserInput(input, history!.current_index); +      } else if ( +        history && +        history.timeline[history.current_index].step.name === +          "Waiting for user confirmation" +      ) { +        onStepUserInput("ok", history!.current_index); +      } else { +        if (input.trim() === "") return; + +        client.sendMainInput(input); +        setUserInputQueue((queue) => { +          return [...queue, input]; +        }); +        mainTextInputRef.current.value = ""; +        mainTextInputRef.current.style.height = ""; +      }      } + +    setWaitingForSteps(true);    };    const onStepUserInput = (input: string, index: number) => { @@ -209,7 +240,14 @@ function GUI(props: GUIProps) {    // const iterations = useSelector(selectIterations);    return ( -    <TopGUIDiv> +    <TopGUIDiv +      ref={topGuiDivRef} +      onKeyDown={(e) => { +        if (e.key === "Enter" && e.ctrlKey) { +          onMainTextInput(); +        } +      }} +    >        {typeof client === "undefined" && (          <>            <Loader></Loader> @@ -249,6 +287,12 @@ function GUI(props: GUIProps) {        </div>        <MainTextInput +        disabled={ +          history +            ? history.timeline[history.current_index].step.name === +              "Waiting for user confirmation" +            : false +        }          ref={mainTextInputRef}          onKeyDown={(e) => {            if (e.key === "Enter") { | 
