summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2019-11-01 08:24:15 +0200
committerYuval Adam <_@yuv.al>2019-11-01 08:24:15 +0200
commit4f09923e065457a945b904ec72caf9630aa7aaf6 (patch)
treefa0fffa9f90647b2ace48924e0d10cb5e732f3e3 /src
parente93a18605076f2c696ee663d6f6b31fbd5023e6c (diff)
parentc647ee0dd2746192c4abb45fa0ea629ac319bcaf (diff)
Merge branch 'patch-1' of https://github.com/LeonFedotov/geshem into LeonFedotov-patch-1
Diffstat (limited to 'src')
-rw-r--r--src/Geshem.js55
1 files changed, 20 insertions, 35 deletions
diff --git a/src/Geshem.js b/src/Geshem.js
index 1163ea8..6128f8d 100644
--- a/src/Geshem.js
+++ b/src/Geshem.js
@@ -22,44 +22,29 @@ 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 buildPlayback = async () => {
- const date = playback;
- const hours = [...Array(24).keys()].map(
- h => `${String(h).padStart(2, "0")}`
- );
- const minutes = [...Array(6).keys()].map(
- m => `${String(m * 10).padStart(2, "0")}`
- );
- const paths = hours.reduce(
- (acc, h) =>
- acc.concat(minutes.map(m => `imgs/${date}/${h}${m}/280.png`)),
- []
- );
- setImages(paths);
- };
+ const fetchImages = async () =>
+ fetch(`${IMAGES_BASE_URL}/imgs.json`)
+ .then(res => res.json())
+ .then(imgs => imgs['280'])
+ .then(setImages)
+ )
+
+ const buildPlayback = async () => setImages(
+ Array(24*6)
+ .fill('')
+ .map((_,i) => `imgs/${playback}/${`${parseInt(i/6, 10)%24}`.padStart(2, '0')}${i%6}0/280.png`)
+ )
+
+ return playback ?
+ (buildPlayback(), () => void 0) :
+ (fetchImages(), ((timer) => () => clearTimer(timer))(setInterval(fetchImages, 60 * 1000))
- let timer;
- if (playback) buildPlayback();
- else {
- fetchImages();
- timer = setInterval(fetchImages, 60 * 1000);
- };
-
- return () => {
- if (timer !== undefined) clearInterval(timer);
- }
- }, [playback]);
+ }, [playback])
return (
<>
@@ -67,7 +52,7 @@ function Geshem(props) {
<DateTime images={images} slider={slider} />
<Slider slider={slider} playback={playback} setSlider={setSlider} />
</>
- );
+ )
}
function getGeolocation() {