diff options
| author | Yuval Adam <_@yuv.al> | 2019-11-01 08:29:57 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2019-11-01 08:29:57 +0200 |
| commit | 14100714d55b9e6b5f636295540614e122ce6af5 (patch) | |
| tree | 4759ce9a447ce6d15209f1ab7a3de2211d3d8648 /src | |
| parent | e93a18605076f2c696ee663d6f6b31fbd5023e6c (diff) | |
Cleanup fetchImages() and URL param parsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/Geshem.js | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/Geshem.js b/src/Geshem.js index 1163ea8..3c816e6 100644 --- a/src/Geshem.js +++ b/src/Geshem.js @@ -22,16 +22,18 @@ function App() { function Geshem(props) { const [images, setImages] = useState([]); const [playback] = useState( - props.match.params.date || window.location.search.slice(-8) || false + props.match.params.date || + new URL(window.location).searchParams.get("history") || + false ); const [slider, setSlider] = useState(playback ? 143 : 9); useEffect(() => { - const fetchImages = async () => { - const res = await fetch(`${IMAGES_BASE_URL}/imgs.json`); - const imgs = await res.json(); - setImages(imgs["280"]); - }; + const fetchImages = async () => + fetch(`${IMAGES_BASE_URL}/imgs.json`) + .then(res => res.json()) + .then(imgs => imgs["280"]) + .then(setImages); const buildPlayback = async () => { const date = playback; @@ -54,11 +56,11 @@ function Geshem(props) { else { fetchImages(); timer = setInterval(fetchImages, 60 * 1000); - }; + } return () => { if (timer !== undefined) clearInterval(timer); - } + }; }, [playback]); return ( |
