From d1b64ddd78d8b8dc3eca76038a75071ab2a575d9 Mon Sep 17 00:00:00 2001 From: Arne Rief 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; + +type Props = { robots: Robot[]; }; + +function RobotList({ robots }: Props) { + const [expandedRobots, setExpandedRobots] = useState( + {} + ); + + function toggleRobotHistory(robotId: number) { + setExpandedRobots((prev) => ({ + ...prev, + [robotId]: !prev[robotId], + })); + } + + return ( +
    + {robots.map((robot) => { + const isExpanded = expandedRobots[robot?.id]; + + return ( +
  • +

    {robot?.name}

    + +

    + Status:{" "} + + {robot?.status} + +

    + +

    Position:

    +
      +
    • Lat: {robot?.lat}
    • +
    • Lon: {robot?.lon}
    • +
    + + + +
    +
      + {robot?.robot_positions?.length ? ( + robot?.robot_positions?.map( + (pos, index) => ( +
    • + {`Lat: ${pos?.lat}, Lon: ${pos?.lon}`} +
    • + ) + ) + ) : ( +
    • + No previous positions. +
    • + )} +
    +
    +
  • + ); + })} +
+ ); +} + +export default RobotList; + -- cgit v1.2.3