import React, { useCallback, useEffect, useState } from "react"; import styled from "styled-components"; import { StyledTooltip, defaultBorderRadius, lightGray, secondaryDark, vscForeground, } from "."; import { PaperAirplaneIcon, SparklesIcon, XMarkIcon, } from "@heroicons/react/24/outline"; import { useSelector } from "react-redux"; import { RootStore } from "../redux/store"; import HeaderButtonWithText from "./HeaderButtonWithText"; const Div = styled.div<{ isDisabled: boolean }>` border-radius: ${defaultBorderRadius}; cursor: ${(props) => (props.isDisabled ? "not-allowed" : "pointer")}; padding: 8px 8px; background-color: ${secondaryDark}; border: 1px solid transparent; display: flex; justify-content: space-between; align-items: center; color: ${(props) => (props.isDisabled ? lightGray : vscForeground)}; &:hover { border: ${(props) => props.isDisabled ? "1px solid transparent" : `1px solid ${lightGray}`}; } `; const P = styled.p` font-size: 13px; margin: 0; `; interface SuggestionsDivProps { title: string; description: string; textInput: string; onClick?: () => void; disabled: boolean; } function SuggestionsDiv(props: SuggestionsDivProps) { const [isHovered, setIsHovered] = useState(false); return ( <>
{ if (props.disabled) return; setIsHovered(true); }} onMouseLeave={() => setIsHovered(false)} isDisabled={props.disabled} >

{props.description}

); } const stageDescriptions = [

Ask a question

,
  1. Highlight code in the editor
  2. Press cmd+M to select the code
  3. Ask a question
,
  1. Highlight code in the editor
  2. Press cmd+shift+M to select the code
  3. Request and edit
, ]; const suggestionsStages: any[][] = [ [ { title: stageDescriptions[0], description: "How does merge sort work?", textInput: "How does merge sort work?", }, { title: stageDescriptions[0], description: "How do I sum over a column in SQL?", textInput: "How do I sum over a column in SQL?", }, ], [ { title: stageDescriptions[1], description: "Is there any way to make this code more efficient?", textInput: "Is there any way to make this code more efficient?", }, { title: stageDescriptions[1], description: "What does this function do?", textInput: "What does this function do?", }, ], [ { title: stageDescriptions[2], description: "/edit write comments for this code", textInput: "/edit write comments for this code", }, { title: stageDescriptions[2], description: "/edit make this code more efficient", textInput: "/edit make this code more efficient", }, ], ]; const TutorialDiv = styled.div` margin: 4px; position: relative; background-color: #ff02; border-radius: ${defaultBorderRadius}; padding: 8px 4px; `; function SuggestionsArea(props: { onClick: (textInput: string) => void }) { const [stage, setStage] = useState( parseInt(localStorage.getItem("stage") || "0") ); const timeline = useSelector( (state: RootStore) => state.serverState.history.timeline ); const sessionId = useSelector( (state: RootStore) => state.serverState.session_info?.session_id ); const codeIsHighlighted = useSelector((state: RootStore) => state.serverState.selected_context_items.some( (item) => item.description.id.provider_title === "code" ) ); const [hide, setHide] = useState(false); useEffect(() => { setHide(false); }, [sessionId]); const [numTutorialInputs, setNumTutorialInputs] = useState(0); const inputsAreOnlyTutorial = useCallback(() => { const inputs = timeline.filter( (node) => !node.step.hide && node.step.name === "User Input" ); return inputs.length - numTutorialInputs === 0; }, [timeline, numTutorialInputs]); return ( <> {hide || stage > 2 || !inputsAreOnlyTutorial() || (
Tutorial

{stage < suggestionsStages.length && suggestionsStages[stage][0]?.title}

{ console.log("HIDE"); setHide(true); }} >
{suggestionsStages[stage]?.map((suggestion) => ( 0 && !codeIsHighlighted} {...suggestion} onClick={() => { if (stage > 0 && !codeIsHighlighted) return; props.onClick(suggestion.textInput); setStage(stage + 1); localStorage.setItem("stage", (stage + 1).toString()); setHide(true); setNumTutorialInputs((prev) => prev + 1); }} /> ))}
)} ); } export default SuggestionsArea;