summaryrefslogtreecommitdiff
path: root/app/components/Geshem.tsx
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2024-09-23 10:29:53 +0200
committerYuval Adam <_@yuv.al>2024-09-23 10:29:53 +0200
commit8a6ff5a2c15422badf0bc9c8166787dc23a71072 (patch)
treeda45cc6fc598520102260da87c3733107ef4e980 /app/components/Geshem.tsx
parent51370d591d4f2ac4eddd8b2ea2f9c5118fbf9ab1 (diff)
Move all geshem/ files to root
Diffstat (limited to 'app/components/Geshem.tsx')
-rw-r--r--app/components/Geshem.tsx80
1 files changed, 80 insertions, 0 deletions
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 (
+// <BrowserRouter>
+// <Routes>
+// <Route path="/" element={<Geshem />} />
+// <Route path="/history/:date" element={<Geshem />} />
+// </Routes>
+// </BrowserRouter>
+// );
+// }
+
+interface GeshemProps {
+ date?: string
+}
+
+export function Geshem({ date }: GeshemProps) {
+ const [images, setImages] = useState<string[]>([]);
+ 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<string[]>(
+ (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 (
+ <>
+ <Map images={images} slider={slider} />
+ <DateTime images={images} slider={slider} />
+ <Slider slider={slider} playback={playback} setSlider={setSlider} />
+ </>
+ );
+}