Skip to content

Commit

Permalink
Front end commands list added
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed Apr 18, 2023
1 parent 831c221 commit 7451899
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 65 deletions.
30 changes: 30 additions & 0 deletions frontend/src/AgentCommandsList.js
Original file line number Diff line number Diff line change
@@ -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 (
<List dense>
{commands &&
commands.map((command, index) => (
<ListItem key={index} disablePadding>
<ListItemButton
onClick={() =>
handleCommandClick(
command,
tabValue === 0 ? setObjective : setInstruction
)
}
>
<Typography variant="body2">{command}</Typography>
</ListItemButton>
</ListItem>
))}
</List>
);
};

export default AgentCommandsList;
71 changes: 41 additions & 30 deletions frontend/src/AgentControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 (
<TextField
{...props}
value={instruction}
onChange={handleInstructionChange}
onKeyPress={handleKeyPress}
/>
);
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 (
Expand Down Expand Up @@ -162,11 +156,14 @@ const AgentControls = ({ darkMode, handleToggleDarkMode, selectedAgent, setChatH
)}
{tabValue === 1 && (
<>
<InstructionInput
<TextField
fullWidth
label="Enter Instruction"
placeholder="Type instruction"
id="instructionInput"
value={instruction}
onChange={(e) => setInstruction(e.target.value)}
onKeyPress={handleKeyPress}
sx={{ mb: 2 }}
/>
<Button
Expand Down Expand Up @@ -194,6 +191,20 @@ const AgentControls = ({ darkMode, handleToggleDarkMode, selectedAgent, setChatH
))}
</Paper>
</Box>
<AgentCommandsList
commands={commands}
tabValue={tabValue}
setObjective={setObjective}
setInstruction={setInstruction}
objective={objective}
instruction={instruction}
/>
<AgentCommandsList
commands={commands}
tabValue={tabValue}
setObjective={setObjective}
setInstruction={setInstruction}
/>
</>
);
};
Expand Down
82 changes: 47 additions & 35 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import {
Container,
Box,
Grid,
List,
ListItem,
Typography,
} from "@mui/material";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import CssBaseline from "@mui/material/CssBaseline";
import AgentList from "./AgentList";
import AgentControls from "./AgentControls";
import AppHeader from "./AppHeader";
import AgentCommandsList from "./AgentCommandsList";

const themeGenerator = (darkMode) =>
createTheme({
Expand All @@ -31,6 +30,10 @@ function App() {
const [loading, setLoading] = useState(false);
const [baseURI, setBaseURI] = useState("");
const [chatHistory, setChatHistory] = useState([]);
const [tabValue, setTabValue] = useState(0);
const [objective, setObjective] = useState("");
const [instruction, setInstruction] = useState("");

async function getBaseURI() {
try {
const response = await fetch("http://127.0.0.1:5000/api/docs");
Expand Down Expand Up @@ -129,40 +132,49 @@ function App() {
<AppHeader darkMode={darkMode} handleToggleDarkMode={handleToggleDarkMode} />
<Container maxWidth="lg">
<Box sx={{ my: 4, display: "flex" }}>
<Grid container spacing={2}>
<Grid item xs={3}>
<AgentList
agents={agents}
selectedAgent={selectedAgent}
setSelectedAgent={setSelectedAgent}
handleAddAgent={handleAddAgent}
handleDeleteAgent={handleDeleteAgent}
loading={loading}
/>
</Grid>
<Grid item xs={6}>
<AgentControls
darkMode={darkMode}
handleToggleDarkMode={handleToggleDarkMode}
selectedAgent={selectedAgent}
setChatHistory={setChatHistory}
chatHistory={chatHistory}
/>
</Grid>
<Grid item xs={3}>
<Typography variant="h6" gutterBottom>
Available Commands:
</Typography>
<List dense>
{commands &&
commands.map((command, index) => (
<ListItem key={index}>
<Typography>{command}</Typography>
</ListItem>
))}
</List>
<Grid container spacing={2}>
<Grid item xs={3}>
<AgentList
agents={agents}
selectedAgent={selectedAgent}
setSelectedAgent={setSelectedAgent}
handleAddAgent={handleAddAgent}
handleDeleteAgent={handleDeleteAgent}
loading={loading}
/>
</Grid>
<Grid item xs={6}>
<AgentControls
darkMode={darkMode}
handleToggleDarkMode={handleToggleDarkMode}
selectedAgent={selectedAgent}
setChatHistory={setChatHistory}
chatHistory={chatHistory}
tabValue={tabValue}
setTabValue={setTabValue}
objective={objective}
setObjective={setObjective}
instruction={instruction}
setInstruction={setInstruction}
/>
</Grid>
<Grid item xs={3}>
<Typography variant="h6" gutterBottom>
Available Commands:
</Typography>
<Typography variant="body2" gutterBottom>
Click on a command to insert it in the textbox.
</Typography>
<AgentCommandsList
commands={commands}
tabValue={tabValue}
setObjective={setObjective}
setInstruction={setInstruction}
objective={objective}
instruction={instruction}
/>
</Grid>
</Grid>
</Grid>
</Box>
</Container>
</ThemeProvider>
Expand Down

0 comments on commit 7451899

Please sign in to comment.