blob: bdfadad700b353e9d0596f05937e45151e32ce08 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
import { useState, type Dispatch, type SetStateAction } from "react";
import API_URL from "../config";
import "../styles/button.css";
import "../styles/sidebar.css";
import type { Robot } from "../types/robot";
import AddRobotForm from "./AddRobotForm";
import ErrorBanner from "./ErrorBanner";
import RobotList from "./RobotList";
import SimulationActions from "./SimulationActions";
type Props = {
activeSimulation: boolean;
errorMessage: string;
robots: Robot[];
token: string | null;
setActiveSimulation: Dispatch<SetStateAction<boolean>>;
setErrorMessage: Dispatch<SetStateAction<string>>;
setRobots: Dispatch<SetStateAction<Robot[]>>;
};
function Sidebar({
activeSimulation,
errorMessage,
robots,
token,
setActiveSimulation,
setErrorMessage,
setRobots,
}: Props) {
const [isAddingRobot, setIsAddingRobot] = useState(false);
function handleAddClick() {
setIsAddingRobot(true);
setErrorMessage("");
}
return (
<div className="sidebar">
<div className="sidebar-robots-header">
<h2>Your Robots</h2>
<button
className="btn btn-add-robot"
onClick={handleAddClick}
disabled={isAddingRobot}
>
+ Add
</button>
</div>
{isAddingRobot && (
<AddRobotForm
apiUrl={API_URL}
errorMessage={errorMessage}
robots={robots}
token={token}
setErrorMessage={setErrorMessage}
setIsAddingRobot={setIsAddingRobot}
setRobots={setRobots}
/>
)}
{errorMessage && <ErrorBanner message={errorMessage} />}
<SimulationActions
activeSimulation={activeSimulation}
apiUrl={API_URL}
token={token}
setActiveSimulation={setActiveSimulation}
setErrorMessage={setErrorMessage}
/>
<RobotList
apiUrl={API_URL}
robots={robots}
token={token}
setErrorMessage={setErrorMessage}
/>
</div>
);
}
export default Sidebar;
|