diff --git a/src/App.tsx b/src/App.tsx index f01d80b1..57077d83 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,7 +10,7 @@ import { useDeviceStore } from "@core/stores/deviceStore.js"; import { CommandPalette } from "./components/CommandPalette/Index.js"; import { DeviceSelector } from "./components/DeviceSelector.js"; import { DialogManager } from "./components/Dialog/DialogManager.js"; -import { Drawer } from "./components/Drawer.js"; +import { Drawer } from "./components/Drawer/index.js"; import { NewDevice } from "./components/NewDevice.js"; import { PageNav } from "./components/PageNav.js"; import { Sidebar } from "./components/Sidebar.js"; diff --git a/src/components/Drawer.tsx b/src/components/Drawer.tsx deleted file mode 100644 index 4b1356e3..00000000 --- a/src/components/Drawer.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import type React from "react"; -import { useState } from "react"; - -import { useDevice } from "@app/core/providers/useDevice.js"; -import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline"; - -export const Drawer = (): JSX.Element => { - const [drawerOpen, setDrawerOpen] = useState(false); - - const tabs = [{ title: "Notifications" }, { title: "Debug" }]; - - const { config, moduleConfig, hardware, nodes, waypoints, connection } = - useDevice(); - - const [serialLogs, setSerialLogs] = useState(""); - - connection?.onDeviceDebugLog.subscribe((packet) => { - setSerialLogs(serialLogs + new TextDecoder().decode(packet)); - }); - - return ( -
-
-
{ - setDrawerOpen(!drawerOpen); - }} - className="ml-auto flex px-2 hover:cursor-pointer hover:bg-slate-100" - > -
- {drawerOpen ? ( - - ) : ( - - )} -
-
-
-
-
- {serialLogs.split("\n").map((line, index) => ( -
- {line} -
- ))} -
-
-
- ); -}; diff --git a/src/components/Drawer/Metrics.tsx b/src/components/Drawer/Metrics.tsx new file mode 100644 index 00000000..b240c0b4 --- /dev/null +++ b/src/components/Drawer/Metrics.tsx @@ -0,0 +1,98 @@ +import "chartjs-adapter-date-fns"; + +import type React from "react"; + +import { + Chart as ChartJS, + Filler, + Legend, + LinearScale, + LineElement, + PointElement, + TimeSeriesScale, + Tooltip +} from "chart.js"; +import { Line } from "react-chartjs-2"; + +import { useDevice } from "@app/core/providers/useDevice.js"; + +export const Metrics = (): JSX.Element => { + const { nodes, hardware } = useDevice(); + + const myNode = nodes.find((n) => n.data.num === hardware.myNodeNum); + + ChartJS.register( + LinearScale, + PointElement, + LineElement, + Tooltip, + Filler, + Legend, + TimeSeriesScale + ); + + return ( +
+ {/* {myNode?.deviceMetrics.map((metric) => ( +

{metric.airUtilTx}

+ ))} */} + { + return { + x: metric.timestamp, + y: metric.airUtilTx + }; + }) + }, + { + fill: true, + label: "channelUtilization", + data: myNode?.deviceMetrics.map((metric) => { + return { + x: metric.timestamp, + y: metric.channelUtilization + }; + }) + }, + { + fill: true, + label: "batteryLevel", + data: myNode?.deviceMetrics.map((metric) => { + return { + x: metric.timestamp, + y: metric.batteryLevel + }; + }) + }, + { + fill: true, + label: "voltage", + data: myNode?.deviceMetrics.map((metric) => { + return { + x: metric.timestamp, + y: metric.voltage + }; + }) + } + ] + }} + /> +
+ ); +}; diff --git a/src/components/Drawer/Notifications.tsx b/src/components/Drawer/Notifications.tsx new file mode 100644 index 00000000..ad994937 --- /dev/null +++ b/src/components/Drawer/Notifications.tsx @@ -0,0 +1,3 @@ +export const Notifications = (): JSX.Element => { + return
; +}; diff --git a/src/components/Drawer/index.tsx b/src/components/Drawer/index.tsx new file mode 100644 index 00000000..9f44e97f --- /dev/null +++ b/src/components/Drawer/index.tsx @@ -0,0 +1,65 @@ +import type React from "react"; +import { useState } from "react"; + +import { Tab } from "@headlessui/react"; +import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline"; + +import type { TabType } from "../layout/page/TabbedContent.js"; +import { Metrics } from "./Metrics.js"; +import { Notifications } from "./Notifications.js"; + +export const Drawer = (): JSX.Element => { + const [drawerOpen, setDrawerOpen] = useState(false); + + const tabs: TabType[] = [ + { name: "Notifications", element: Notifications }, + { name: "Metrics", element: Metrics } + ]; + return ( + + + {tabs.map((tab, index) => ( + + {({ selected }) => ( +
{ + setDrawerOpen(true); + }} + className={`flex h-full cursor-pointer px-1 first:pl-2 last:pr-2 hover:bg-orange-300 ${ + selected ? "bg-orange-500 text-white" : "bg-white text-black" + }`} + > + {tab.name} +
+ )} +
+ ))} + +
+
{ + setDrawerOpen(!drawerOpen); + }} + className="flex cursor-pointer px-2" + > +
+ {drawerOpen ? ( + + ) : ( + + )} +
+
+
+
+ + + {tabs.map((tab, index) => ( + + {tab.element} + + ))} + +
+ ); +}; diff --git a/src/components/Widgets/PeersWidget.tsx b/src/components/Widgets/PeersWidget.tsx index 7e816ca5..a9899f5d 100644 --- a/src/components/Widgets/PeersWidget.tsx +++ b/src/components/Widgets/PeersWidget.tsx @@ -23,9 +23,7 @@ export const PeersWidget = ({ peers }: PeersWidgetProps): JSX.Element => {
-

- Connected Peers -

+

Peers

{peers.length > 0 ? (

diff --git a/src/core/subscriptions.ts b/src/core/subscriptions.ts index 445b7444..cf383fce 100644 --- a/src/core/subscriptions.ts +++ b/src/core/subscriptions.ts @@ -21,8 +21,6 @@ export const subscribeAll = ( }); connection.onTelemetryPacket.subscribe((telemetryPacket) => { - console.log(telemetryPacket.data.variant); - device.setMetrics(telemetryPacket); });