Improvements to node filtering and storage (#839)
* Improves node filtering and voltage display Ensures voltage values are always displayed as positive. Enhances node filtering logic to handle unknown or undefined values, preventing nodes from being unexpectedly hidden. Updates UI labels for clarity. Improves Nodes page responsiveness by debouncing node updates and optimizing selector usage, preventing unnecessary re-renders. Adds validation warnings for key conflicts between nodes. * Update packages/web/src/core/stores/nodeDBStore/nodeDBStore.test.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/web/src/core/stores/nodeDBStore/nodeValidation.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Revert copilot suggestion * Review changes --------- Co-authored-by: philon- <philon-@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot
philon-
parent
52fd2f712c
commit
3e2fe721d3
@@ -11,11 +11,19 @@ import { cn } from "@core/utils/cn.ts";
|
||||
import type { Protobuf } from "@meshtastic/core";
|
||||
import { bbox, lineString } from "@turf/turf";
|
||||
import { FunnelIcon, MapPinIcon } from "lucide-react";
|
||||
import { useCallback, useDeferredValue, useMemo, useState } from "react";
|
||||
import {
|
||||
useCallback,
|
||||
useDeferredValue,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { Marker, Popup, useMap } from "react-map-gl/maplibre";
|
||||
import { NodeDetail } from "../../components/PageComponents/Map/NodeDetail.tsx";
|
||||
import { Avatar } from "../../components/UI/Avatar.tsx";
|
||||
|
||||
const NODEDB_DEBOUNCE_MS = 250;
|
||||
|
||||
type NodePosition = {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
@@ -31,7 +39,19 @@ const convertToLatLng = (position?: {
|
||||
|
||||
const MapPage = () => {
|
||||
const { waypoints } = useDevice();
|
||||
const { getNodes, hasNodeError } = useNodeDB();
|
||||
const { nodes: validNodes, hasNodeError } = useNodeDB(
|
||||
(db) => ({
|
||||
// only nodes with a position
|
||||
nodes: db.getNodes((n): n is Protobuf.Mesh.NodeInfo =>
|
||||
Boolean(n.position?.latitudeI),
|
||||
),
|
||||
hasNodeError: db.hasNodeError,
|
||||
// include the Map reference so error badges update when nodeErrors changes
|
||||
_errorsRef: db.nodeErrors,
|
||||
}),
|
||||
{ debounce: NODEDB_DEBOUNCE_MS },
|
||||
);
|
||||
|
||||
const { nodeFilter, defaultFilterValues, isFilterDirty } = useFilterNode();
|
||||
|
||||
const { default: map } = useMap();
|
||||
@@ -39,14 +59,6 @@ const MapPage = () => {
|
||||
const [selectedNode, setSelectedNode] =
|
||||
useState<Protobuf.Mesh.NodeInfo | null>(null);
|
||||
|
||||
const validNodes = useMemo(
|
||||
() =>
|
||||
getNodes((node): node is Protobuf.Mesh.NodeInfo =>
|
||||
Boolean(node.position?.latitudeI),
|
||||
),
|
||||
[getNodes],
|
||||
);
|
||||
|
||||
const [filterState, setFilterState] = useState<FilterState>(
|
||||
() => defaultFilterValues,
|
||||
);
|
||||
@@ -57,6 +69,8 @@ const MapPage = () => {
|
||||
[validNodes, deferredFilterState, nodeFilter],
|
||||
);
|
||||
|
||||
const hasFitBoundsOnce = useRef(false);
|
||||
|
||||
const handleMarkerClick = useCallback(
|
||||
(node: Protobuf.Mesh.NodeInfo, event: { originalEvent: MouseEvent }) => {
|
||||
event?.originalEvent?.stopPropagation();
|
||||
@@ -76,7 +90,7 @@ const MapPage = () => {
|
||||
|
||||
// Get the bounds of the map based on the nodes furtherest away from center
|
||||
const getMapBounds = useCallback(() => {
|
||||
if (!map || validNodes.length === 0) {
|
||||
if (hasFitBoundsOnce.current || !map || validNodes.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -108,6 +122,7 @@ const MapPage = () => {
|
||||
if (center) {
|
||||
map.easeTo(center);
|
||||
}
|
||||
hasFitBoundsOnce.current = true;
|
||||
}, [map, validNodes]);
|
||||
|
||||
// Generate all markers
|
||||
|
||||
Reference in New Issue
Block a user