Skip to content

Commit f7c3be0

Browse files
cj-vanaclaude
andcommitted
Hide stale nodes from map - show only nodes seen in last 24 hours
- Add MAP_VISIBILITY_THRESHOLD_MS constant (24 hours) - Filter map nodes by last_seen timestamp - Update stats overlay to show "active nodes" and filter info 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 189d27a commit f7c3be0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/components/NetworkMap.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet';
55
import L from 'leaflet';
66
import 'leaflet/dist/leaflet.css';
77
import type { NodeWithStats } from '@/lib/types';
8+
import { MAP_VISIBILITY_THRESHOLD_MS } from '@/lib/constants';
89

910
// Fix for default marker icons in Next.js - only run on client
1011
if (typeof window !== 'undefined') {
@@ -70,6 +71,17 @@ function getNodeColor(node: NodeWithStats): string {
7071
return NODE_COLORS[node.node_type] || DEFAULT_NODE_COLOR;
7172
}
7273

74+
/**
75+
* Check if a node was seen within the map visibility threshold (24 hours)
76+
*/
77+
function isNodeRecentlyActive(node: NodeWithStats): boolean {
78+
if (!node.last_seen) return false;
79+
const lastSeenTime = node.last_seen.endsWith('Z')
80+
? new Date(node.last_seen).getTime()
81+
: new Date(node.last_seen + 'Z').getTime();
82+
return Date.now() - lastSeenTime < MAP_VISIBILITY_THRESHOLD_MS;
83+
}
84+
7385
interface NetworkMapProps {
7486
nodes?: NodeWithStats[];
7587
className?: string;
@@ -115,9 +127,9 @@ export function NetworkMap({ nodes, className = '' }: NetworkMapProps) {
115127
fetchNodes();
116128
}, [nodes]);
117129

118-
// Filter nodes with valid coordinates
130+
// Filter nodes with valid coordinates AND seen within 24 hours
119131
const nodesWithLocation = mapNodes.filter(
120-
(node) => node.latitude !== null && node.longitude !== null
132+
(node) => node.latitude !== null && node.longitude !== null && isNodeRecentlyActive(node)
121133
);
122134

123135
// Calculate map bounds if we have nodes
@@ -243,10 +255,13 @@ export function NetworkMap({ nodes, className = '' }: NetworkMapProps) {
243255
<div className="absolute top-4 right-4 bg-night-900/90 backdrop-blur-sm rounded-lg p-3 z-[1000]">
244256
<div className="text-sm text-foreground">
245257
<span className="text-mesh font-bold">{nodesWithLocation.length}</span>
246-
<span className="text-foreground-muted"> nodes with location</span>
258+
<span className="text-foreground-muted"> active nodes</span>
247259
</div>
248260
<div className="text-xs text-foreground-muted">
249-
{nodesWithLocation.filter(n => n.is_online).length} online
261+
{nodesWithLocation.filter(n => n.is_online).length} online now
262+
</div>
263+
<div className="text-[10px] text-foreground-muted/70 mt-1">
264+
Showing nodes seen in last 24h
250265
</div>
251266
</div>
252267
</div>

src/lib/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export const API_CACHE_TIMES = {
4444
/** Online threshold in milliseconds (15 minutes) */
4545
export const ONLINE_THRESHOLD_MS = 15 * 60 * 1000;
4646

47+
/** Map visibility threshold in milliseconds (24 hours) - nodes not seen within this time are hidden from map */
48+
export const MAP_VISIBILITY_THRESHOLD_MS = 24 * 60 * 60 * 1000;
49+
4750
/** Default refresh interval for live data (1 minute) */
4851
export const DEFAULT_REFRESH_INTERVAL = 60000;
4952

0 commit comments

Comments
 (0)