import RefreshIcon from "@mui/icons-material/Refresh"; import { IconButton, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Tooltip, } from "@mui/material"; import React from "react"; import { Device, DeviceApi, DeviceRelay, DeviceURL } from "../api/DeviceApi"; import { RelayApi, RelaysStatus } from "../api/RelayApi"; import { AsyncWidget } from "../widgets/AsyncWidget"; import { BoolText } from "../widgets/BoolText"; import { SolarEnergyRouteContainer } from "../widgets/SolarEnergyRouteContainer"; import { TimeWidget } from "../widgets/TimeWidget"; import { useNavigate } from "react-router-dom"; export function RelaysListRoute(p: { homeWidget?: boolean; }): React.ReactElement { const loadKey = React.useRef(1); const [list, setList] = React.useState(); const [devices, setDevices] = React.useState(); const [status, setStatus] = React.useState(); const load = async () => { setList(await RelayApi.GetList()); setDevices(await DeviceApi.ValidatedList()); setStatus(await RelayApi.GetRelaysStatus()); list?.sort((a, b) => b.priority - a.priority); }; const reload = () => { loadKey.current += 1; setList(undefined); }; return ( <> } > ( )} /> ); } function RelaysList(p: { list: DeviceRelay[]; devices: Device[]; status: RelaysStatus; onReload: () => void; }): React.ReactElement { const navigate = useNavigate(); const openDevicePage = (relay: DeviceRelay) => { const dev = p.devices.find((d) => d.relays.find((r) => r.id === relay.id)); navigate(DeviceURL(dev!)); }; return ( Name Enabled Priority Consumption Status {p.list.map((row) => ( openDevicePage(row)} > {row.name} {row.priority} {row.consumption} {" "} for ))}
); }