scaffolding for a timestamp
This commit is contained in:
@@ -49,12 +49,14 @@ const WeatherMap = ({ zoom, dark }) => {
|
|||||||
const [currentMapTimestampIdx, setCurrentMapTimestampIdx] = useState(0);
|
const [currentMapTimestampIdx, setCurrentMapTimestampIdx] = useState(0);
|
||||||
|
|
||||||
const MAP_TIMESTAMP_REFRESH_FREQUENCY = 1000 * 60 * 10; //update every 10 minutes
|
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(), [
|
const getMapApiKeyCallback = useCallback(() => getMapApiKey(), [
|
||||||
getMapApiKey,
|
getMapApiKey,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
//const delay = ms => new Promise(res => setTimeout(res, ms));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getMapApiKeyCallback().catch((err) => {
|
getMapApiKeyCallback().catch((err) => {
|
||||||
console.log("err!", err);
|
console.log("err!", err);
|
||||||
@@ -101,16 +103,21 @@ const WeatherMap = ({ zoom, dark }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (mapTimestamps) {
|
if (mapTimestamps) {
|
||||||
if (animateWeatherMap) {
|
if (animateWeatherMap) {
|
||||||
|
let cycleRate = MAP_CYCLE_RATE;
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
let nextIdx;
|
let nextIdx;
|
||||||
|
//let d = new Date(mapTimestamps[currentMapTimestampIdx]*1000);
|
||||||
|
//console.log(d.toTimeString());
|
||||||
if (currentMapTimestampIdx + 1 >= mapTimestamps.length) {
|
if (currentMapTimestampIdx + 1 >= mapTimestamps.length) {
|
||||||
nextIdx = 0;
|
nextIdx = 0;
|
||||||
|
cycleRate = 5000;
|
||||||
} else {
|
} else {
|
||||||
nextIdx = currentMapTimestampIdx + 1;
|
nextIdx = currentMapTimestampIdx + 1;
|
||||||
}
|
}
|
||||||
setCurrentMapTimestampIdx(nextIdx);
|
setCurrentMapTimestampIdx(nextIdx);
|
||||||
}, MAP_CYCLE_RATE);
|
}, cycleRate);
|
||||||
return () => {
|
return () => {
|
||||||
|
//console.log(cycleRate);
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user