From d1b64ddd78d8b8dc3eca76038a75071ab2a575d9 Mon Sep 17 00:00:00 2001
From: Arne Rief <riearn@proton.me>
Date: Mon, 22 Dec 2025 12:56:20 +0100
Subject: Sidebar split into smaller components

---
 frontend/src/components/RobotList.tsx | 84 +++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 frontend/src/components/RobotList.tsx

(limited to 'frontend/src/components/RobotList.tsx')

diff --git a/frontend/src/components/RobotList.tsx b/frontend/src/components/RobotList.tsx
new file mode 100644
index 0000000..d711372
--- /dev/null
+++ b/frontend/src/components/RobotList.tsx
@@ -0,0 +1,84 @@
+import { useState } from "react";
+import type { Robot } from "../types/robot";
+
+type ExpandedRobotsState = Record<number, boolean>;
+
+type Props = { robots: Robot[]; };
+
+function RobotList({ robots }: Props) {
+    const [expandedRobots, setExpandedRobots] = useState<ExpandedRobotsState>(
+        {}
+    );
+
+    function toggleRobotHistory(robotId: number) {
+        setExpandedRobots((prev) => ({
+            ...prev,
+            [robotId]: !prev[robotId],
+        }));
+    }
+
+    return (
+        <ul className="sidebar-robot-list">
+            {robots.map((robot) => {
+                const isExpanded = expandedRobots[robot?.id];
+
+                return (
+                    <li key={robot?.id}>
+                        <p className="robot-name">{robot?.name}</p>
+
+                        <p>
+                            Status:{" "}
+                            <span className={`robot-status-${robot?.status}`}>
+                                {robot?.status}
+                            </span>
+                        </p>
+
+                        <p className="robot-coordinates-label">Position:</p>
+                        <ul className="robot-coordinates">
+                            <li>Lat: {robot?.lat}</li>
+                            <li>Lon: {robot?.lon}</li>
+                        </ul>
+
+                        <button
+                            className="btn btn-robot-history-toggle"
+                            onClick={() => toggleRobotHistory(robot?.id)}
+                            aria-expanded={isExpanded}
+                        >
+                            Position history
+                            <span
+                                className={`arrow ${isExpanded ? "open" : ""}`}
+                            >
+                                ▾
+                            </span>
+                        </button>
+
+                        <div
+                            className={`robot-history ${
+                                isExpanded ? "expanded" : ""
+                            }`}
+                        >
+                            <ul>
+                                {robot?.robot_positions?.length ? (
+                                    robot?.robot_positions?.map(
+                                        (pos, index) => (
+                                            <li key={index}>
+                                                {`Lat: ${pos?.lat}, Lon: ${pos?.lon}`}
+                                            </li>
+                                        )
+                                    )
+                                ) : (
+                                    <li className="robot-history-empty">
+                                        No previous positions.
+                                    </li>
+                                )}
+                            </ul>
+                        </div>
+                    </li>
+                );
+            })}
+        </ul>
+    );
+}
+
+export default RobotList;
+
-- 
cgit v1.2.3

