From 7451899af8c0b841a993314177af0abb58d0be56 Mon Sep 17 00:00:00 2001 From: Josh XT Date: Tue, 18 Apr 2023 17:56:57 -0400 Subject: [PATCH] Front end commands list added --- frontend/src/AgentCommandsList.js | 30 +++++++++++ frontend/src/AgentControls.js | 71 +++++++++++++++----------- frontend/src/App.js | 82 ++++++++++++++++++------------- 3 files changed, 118 insertions(+), 65 deletions(-) create mode 100644 frontend/src/AgentCommandsList.js diff --git a/frontend/src/AgentCommandsList.js b/frontend/src/AgentCommandsList.js new file mode 100644 index 000000000000..3aedafca64ea --- /dev/null +++ b/frontend/src/AgentCommandsList.js @@ -0,0 +1,30 @@ +import React from 'react'; +import { List, ListItem, ListItemButton, Typography } from '@mui/material'; + +const AgentCommandsList = ({ commands, tabValue, setObjective, setInstruction }) => { + const handleCommandClick = (command, setText) => { + setText((prevText) => prevText + command + " for "); + }; + + return ( + + {commands && + commands.map((command, index) => ( + + + handleCommandClick( + command, + tabValue === 0 ? setObjective : setInstruction + ) + } + > + {command} + + + ))} + + ); +}; + +export default AgentCommandsList; \ No newline at end of file diff --git a/frontend/src/AgentControls.js b/frontend/src/AgentControls.js index 1f6edb77f83e..8c759330593f 100644 --- a/frontend/src/AgentControls.js +++ b/frontend/src/AgentControls.js @@ -8,10 +8,22 @@ import { Tab, Tabs, } from "@mui/material"; +import AgentCommandsList from "./AgentCommandsList"; -const AgentControls = ({ darkMode, handleToggleDarkMode, selectedAgent, setChatHistory, chatHistory }) => { - const [objective, setObjective] = useState(""); - const [tabValue, setTabValue] = useState(0); +const AgentControls = ({ + darkMode, + handleToggleDarkMode, + selectedAgent, + setChatHistory, + chatHistory, + commands, + tabValue, + setTabValue, + objective, + setObjective, + instruction, + setInstruction, +}) => { const [baseURI, setBaseURI] = useState(""); async function getBaseURI() { @@ -104,35 +116,17 @@ const AgentControls = ({ darkMode, handleToggleDarkMode, selectedAgent, setChatH ]); }; - const InstructionInput = (props) => { - const [instruction, setInstruction] = useState(""); - - const handleInstructionChange = (event) => { - setInstruction(event.target.value); - }; - - const handleKeyPress = async (event) => { - if (event.key === "Enter") { - event.preventDefault(); - await InstructAgent(instruction); - setInstruction(""); - } - }; - - return ( - - ); + const handleKeyPress = async (event) => { + if (event.key === "Enter") { + event.preventDefault(); + await InstructAgent(instruction); + setInstruction(""); + } }; const handleSendInstruction = async () => { - const instructionInput = document.getElementById("instructionInput"); - await InstructAgent(instructionInput.value); - instructionInput.value = ""; + await InstructAgent(instruction); + setInstruction(""); }; return ( @@ -162,11 +156,14 @@ const AgentControls = ({ darkMode, handleToggleDarkMode, selectedAgent, setChatH )} {tabValue === 1 && ( <> - setInstruction(e.target.value)} + onKeyPress={handleKeyPress} sx={{ mb: 2 }} />