@@ -79,7 +79,7 @@ export function BaseMap({ onMapLoaded, onCleanup }: { onMapLoaded?: (map: Map) =
7979 const sourceInitializedRef = useRef ( false ) ;
8080 const connectedStationsRef = useRef ( new Set < string > ( ) ) ;
8181
82- const { data : rtsData , error : rtsError } = useRTS ( ) ;
82+ const { data : rtsData , lastUpdate } = useRTS ( ) ;
8383
8484 const [ dataTime , setDataTime ] = useState ( 0 ) ;
8585 const [ maxIntensity , setMaxIntensity ] = useState ( - 3 ) ;
@@ -88,6 +88,8 @@ export function BaseMap({ onMapLoaded, onCleanup }: { onMapLoaded?: (map: Map) =
8888 const [ tooltipSwitchIndex , setTooltipSwitchIndex ] = useState ( 0 ) ;
8989 const [ tooltips , setTooltips ] = useState < AlertTooltip [ ] > ( [ ] ) ;
9090 const [ alertStations , setAlertStations ] = useState < AlertTooltip [ ] > ( [ ] ) ;
91+ const [ isStale , setIsStale ] = useState ( false ) ;
92+ const lastReceivedTimeRef = useRef ( 0 ) ;
9193
9294 const formatTime = ( ts : number ) => {
9395 if ( ! ts ) return '' ;
@@ -232,10 +234,21 @@ export function BaseMap({ onMapLoaded, onCleanup }: { onMapLoaded?: (map: Map) =
232234 } ;
233235 } , [ ] ) ;
234236
237+ // Check stale status on every update (triggered by RTSContext's 1s interval)
238+ useEffect ( ( ) => {
239+ if ( lastUpdate === 0 ) return ;
240+ const now = Date . now ( ) ;
241+ if ( lastReceivedTimeRef . current > 0 ) {
242+ setIsStale ( now - lastReceivedTimeRef . current > 3000 ) ;
243+ }
244+ } , [ lastUpdate ] ) ;
245+
235246 // Process RTS data when it updates
236247 useEffect ( ( ) => {
237248 if ( ! rtsData ) return ;
238249 setDataTime ( rtsData . time ) ;
250+ lastReceivedTimeRef . current = Date . now ( ) ;
251+ setIsStale ( false ) ;
239252 let max = - 3 ;
240253 const alerts : AlertTooltip [ ] = [ ] ;
241254 for ( const f of rtsData . geojson . features ) {
@@ -348,7 +361,7 @@ export function BaseMap({ onMapLoaded, onCleanup }: { onMapLoaded?: (map: Map) =
348361 </ div >
349362 </ div >
350363 < div className = "bg-black/70 backdrop-blur-md rounded-lg px-3 py-1.5 border border-white/10 shadow-lg flex items-center gap-1.5" >
351- < div className = { `w-2 h-2 rounded-full animate-pulse ${ rtsError ? 'bg-red-500' : 'bg-emerald-400' } ` } />
364+ < div className = { `w-2 h-2 rounded-full animate-pulse ${ isStale ? 'bg-red-500' : 'bg-emerald-400' } ` } />
352365 < span className = "text-white/90 text-xs font-medium tracking-wide" > { formatTime ( dataTime ) } </ span >
353366 </ div >
354367 </ div >
0 commit comments