Skip to content

Commit

Permalink
Implement on nodes page
Browse files Browse the repository at this point in the history
  • Loading branch information
KomelT committed Sep 18, 2024
1 parent 2a5acb8 commit 56ac1d5
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions src/pages/Nodes.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { NodeOptionsDialog } from "@app/components/Dialog/NodeOptionsDialog";
import { TracerouteResponseDialog } from "@app/components/Dialog/TracerouteResponseDialog";
import Footer from "@app/components/UI/Footer";
import { useAppStore } from "@app/core/stores/appStore";
import { Sidebar } from "@components/Sidebar.js";
Expand All @@ -7,10 +9,10 @@ import { Table } from "@components/generic/Table/index.js";
import { TimeAgo } from "@components/generic/Table/tmp/TimeAgo.js";
import { useDevice } from "@core/stores/deviceStore.js";
import { Hashicon } from "@emeraldpay/hashicon-react";
import { Protobuf } from "@meshtastic/js";
import { Protobuf, type Types } from "@meshtastic/js";
import { numberToHexUnpadded } from "@noble/curves/abstract/utils";
import { LockIcon, LockOpenIcon, TrashIcon } from "lucide-react";
import { Fragment } from "react";
import { Fragment, useCallback, useEffect, useState } from "react";
import { base16 } from "rfc4648";

export interface DeleteNoteDialogProps {
Expand All @@ -19,13 +21,36 @@ export interface DeleteNoteDialogProps {
}

export const NodesPage = (): JSX.Element => {
const { nodes, hardware, setDialogOpen } = useDevice();
const { nodes, hardware, setDialogOpen, connection } = useDevice();
const { setNodeNumToBeRemoved } = useAppStore();
const [selectedNode, setSelectedNode] = useState<
Protobuf.Mesh.NodeInfo | undefined
>(undefined);
const [selectedTraceroute, setSelectedTraceroute] = useState<
Types.PacketMetadata<Protobuf.Mesh.RouteDiscovery> | undefined
>();

const filteredNodes = Array.from(nodes.values()).filter(
(n) => n.num !== hardware.myNodeNum,
);

useEffect(() => {
connection?.events.onTraceRoutePacket.subscribe(handleTraceroute);
return () => {
connection?.events.onTraceRoutePacket.unsubscribe(handleTraceroute);
};
}, [
connection?.events.onTraceRoutePacket.subscribe,
connection?.events.onTraceRoutePacket.unsubscribe,
]);

const handleTraceroute = useCallback(
(traceroute: Types.PacketMetadata<Protobuf.Mesh.RouteDiscovery>) => {
setSelectedTraceroute(traceroute);
},
[],
);

return (
<>
<Sidebar />
Expand All @@ -45,7 +70,7 @@ export const NodesPage = (): JSX.Element => {
]}
rows={filteredNodes.map((node) => [
<Hashicon key="icon" size={24} value={node.num.toString()} />,
<h1 key="header">
<h1 key="header" onMouseDown={() => setSelectedNode(node)}>
{node.user?.longName ??
(node.user?.macaddr
? `Meshtastic ${base16
Expand Down Expand Up @@ -105,6 +130,16 @@ export const NodesPage = (): JSX.Element => {
</Button>,
])}
/>
<NodeOptionsDialog
node={selectedNode}
open={!!selectedNode}
onOpenChange={() => setSelectedNode(undefined)}
/>
<TracerouteResponseDialog
traceroute={selectedTraceroute}
open={!!selectedTraceroute}
onOpenChange={() => setSelectedTraceroute(undefined)}
/>
</div>
<Footer />
</div>
Expand Down

0 comments on commit 56ac1d5

Please sign in to comment.