import type React from 'react'; import { useEffect, useState } from 'react'; import { m } from 'framer-motion'; import type { Edge, Node } from 'react-flow-renderer'; import ReactFlow, { Background, Controls, MiniMap } from 'react-flow-renderer'; import { BiCrown } from 'react-icons/bi'; import { FiSettings } from 'react-icons/fi'; import { RiMindMap } from 'react-icons/ri'; import { IconButton } from '@components/generic/button/IconButton'; import { Tooltip } from '@components/generic/Tooltip'; import { Layout } from '@components/layout'; import { SidebarItem } from '@components/layout/Sidebar/SidebarItem'; import { Hashicon } from '@emeraldpay/hashicon-react'; import { useAppSelector } from '@hooks/useAppSelector'; export const Nodes = (): JSX.Element => { const [graphNodes, setGraphNodes] = useState([]); const [graphEdges, setGraphEdges] = useState([]); const [selected, setSelected] = useState(0); const nodes = useAppSelector((state) => state.meshtastic.nodes); const myNodeNum = useAppSelector( (state) => state.meshtastic.radio.hardware.myNodeNum, ); useEffect(() => { const tmpNodes: Node[] = []; // User Terminal tmpNodes.push({ id: '1', type: 'input', data: { label: 'User Terminal' }, position: { x: 160 + 500, y: 0 + 500 }, }); nodes.map((node, index) => { tmpNodes.push({ id: node.data.num.toString(), data: { label: node.data.user?.longName ?? `Unknown ${node.data.num}` }, position: { x: index * 160 + 500, y: 100 + 500 }, }); }); setGraphNodes(tmpNodes); }, [nodes, myNodeNum]); useEffect(() => { const tmpEdges: Edge[] = []; nodes.map((node, index) => { if (node.data.num === myNodeNum) { tmpEdges.push({ id: `e${1}-${myNodeNum}`, source: '1', target: myNodeNum.toString(), type: 'smoothstep', style: { stroke: 'yellow', strokeWidth: 2, }, }); } // node.routes.map((route) => { // tmpEdges.push({ // id: `e${route.from}-${route.to}`, // source: node.num.toString(), // target: route.to.toString(), // type: 'smoothstep', // animated: true, // }); // }); }); setGraphEdges(tmpEdges); }, [nodes, myNodeNum]); return ( } sidebarContents={ <> {nodes.map((node) => ( { setSelected(node.data.num); }} actions={ { e.stopPropagation(); setSelected(node.data.num); }} icon={} /> } >
{node.data.num === myNodeNum && ( )}
{node.data.lastHeard ? new Date(node.data.lastHeard).toLocaleTimeString( undefined, { hour: '2-digit', minute: '2-digit', }, ) : 'Never'}
))} } >
); };