@@ -5,6 +5,7 @@ import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet';
55import L from 'leaflet' ;
66import 'leaflet/dist/leaflet.css' ;
77import 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
1011if ( 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+
7385interface 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 >
0 commit comments