From 78bbe26fa881959b4ef1a9f0c9eb7431b052ae2a Mon Sep 17 00:00:00 2001 From: Adam Roe Date: Wed, 14 Aug 2024 19:30:42 +1000 Subject: [PATCH] scaffolding for a timestamp --- client/src/components/WeatherMap/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client/src/components/WeatherMap/index.js b/client/src/components/WeatherMap/index.js index b9e9f20..2cb75c1 100644 --- a/client/src/components/WeatherMap/index.js +++ b/client/src/components/WeatherMap/index.js @@ -49,12 +49,14 @@ const WeatherMap = ({ zoom, dark }) => { const [currentMapTimestampIdx, setCurrentMapTimestampIdx] = useState(0); const MAP_TIMESTAMP_REFRESH_FREQUENCY = 1000 * 60 * 10; //update every 10 minutes - const MAP_CYCLE_RATE = 1000; //ms + const MAP_CYCLE_RATE = 500; //ms const getMapApiKeyCallback = useCallback(() => getMapApiKey(), [ getMapApiKey, ]); + //const delay = ms => new Promise(res => setTimeout(res, ms)); + useEffect(() => { getMapApiKeyCallback().catch((err) => { console.log("err!", err); @@ -101,16 +103,21 @@ const WeatherMap = ({ zoom, dark }) => { useEffect(() => { if (mapTimestamps) { if (animateWeatherMap) { + let cycleRate = MAP_CYCLE_RATE; const interval = setInterval(() => { let nextIdx; + //let d = new Date(mapTimestamps[currentMapTimestampIdx]*1000); + //console.log(d.toTimeString()); if (currentMapTimestampIdx + 1 >= mapTimestamps.length) { nextIdx = 0; + cycleRate = 5000; } else { nextIdx = currentMapTimestampIdx + 1; } setCurrentMapTimestampIdx(nextIdx); - }, MAP_CYCLE_RATE); + }, cycleRate); return () => { + //console.log(cycleRate); clearInterval(interval); }; } else {