From 8a6ff5a2c15422badf0bc9c8166787dc23a71072 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 23 Sep 2024 10:29:53 +0200 Subject: Move all geshem/ files to root --- app/components/Geshem.tsx | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 app/components/Geshem.tsx (limited to 'app/components/Geshem.tsx') diff --git a/app/components/Geshem.tsx b/app/components/Geshem.tsx new file mode 100644 index 0000000..50659be --- /dev/null +++ b/app/components/Geshem.tsx @@ -0,0 +1,80 @@ +"use client" + +import React, { useState, useEffect } from "react"; +// import { BrowserRouter, Route, Routes } from "react-router-dom"; + +import { Map } from "./Map"; +import { Slider } from "./Slider"; +import { DateTime } from "./Datetime"; +import { IMAGES_BASE_URL, PLAYBACK_HOURS, PLAYBACK_SLOTS } from "./config"; + +// import "./Geshem.css"; +import "rc-slider/assets/index.css"; + +// export function App() { +// return ( +// +// +// } /> +// } /> +// +// +// ); +// } + +interface GeshemProps { + date?: string +} + +export function Geshem({ date }: GeshemProps) { + const [images, setImages] = useState([]); + const [playback] = useState( + date || + new URL(window.location.toString()).searchParams.get("history") || + undefined + ); + const [slider, setSlider] = useState(playback ? PLAYBACK_SLOTS : 9); + + useEffect(() => { + 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; + const hours = Array.from(Array(PLAYBACK_HOURS).keys()).map( + h => `${String(h).padStart(2, "0")}` + ); + const minutes = Array.from(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); + }; + + let timer: number; + if (playback) buildPlayback(); + else { + fetchImages(); + timer = window.setInterval(fetchImages, 60 * 1000); + } + + return () => { + if (timer !== undefined) clearInterval(timer); + }; + }, [playback]); + + return ( + <> + + + + + ); +} -- cgit v1.3.1