mirror of
				https://github.com/brianshea2/meshmap.net.git
				synced 2025-03-05 21:00:01 -08:00 
			
		
		
		
	auto update improvements
This commit is contained in:
		
							parent
							
								
									55cdd8a32b
								
							
						
					
					
						commit
						92dcb58981
					
				|  | @ -317,15 +317,19 @@ | ||||||
|     } |     } | ||||||
|   }) |   }) | ||||||
|   // fetches node data, updates map, repeats |   // fetches node data, updates map, repeats | ||||||
|   const drawMap = async shouldDraw => { |   const drawMap = async () => { | ||||||
|     if (shouldDraw) { |     try { | ||||||
|       try { |       await fetch('/nodes.json').then(r => r.json()).then(updateNodes) | ||||||
|         await fetch('/nodes.json').then(r => r.json()).then(updateNodes) |     } catch (e) { | ||||||
|       } catch (e) { |       console.error('Failed to update nodes:', e) | ||||||
|         console.error('Failed to update nodes:', e) |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|     setTimeout(() => drawMap(document.visibilityState === 'visible'), updateInterval) |     setTimeout(() => { | ||||||
|  |       if (document.hidden) { | ||||||
|  |         document.addEventListener('visibilitychange', drawMap, {once: true}) | ||||||
|  |       } else { | ||||||
|  |         drawMap() | ||||||
|  |       } | ||||||
|  |     }, updateInterval) | ||||||
|   } |   } | ||||||
|   // centers map to node and opens popup |   // centers map to node and opens popup | ||||||
|   const showNode = nodeNum => { |   const showNode = nodeNum => { | ||||||
|  | @ -351,7 +355,7 @@ | ||||||
|     } |     } | ||||||
|   }) |   }) | ||||||
|   // let's go!!! |   // let's go!!! | ||||||
|   drawMap(true).then(() => { |   drawMap().then(() => { | ||||||
|     if (window.location.hash && !showNode(window.location.hash.slice(1))) { |     if (window.location.hash && !showNode(window.location.hash.slice(1))) { | ||||||
|       history.replaceState(null, '', window.location.pathname) |       history.replaceState(null, '', window.location.pathname) | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue