From d5cf0f5f273fc5518582fd0cd6b42bafdd6764eb Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 23 Sep 2024 14:32:51 +0200 Subject: Cleanup playback impl --- app/components/Geshem.tsx | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/components/Geshem.tsx b/app/components/Geshem.tsx index 9f6e5f4..ba67b34 100644 --- a/app/components/Geshem.tsx +++ b/app/components/Geshem.tsx @@ -23,18 +23,24 @@ export function Geshem() { .then(setImages); const buildPlayback = async () => { - const date = fragment; - 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`)), - [] - ); + if (fragment === undefined) return; + const date = fragment.slice(0, 8); + const startHour = parseInt(fragment.slice(8, 10)) || 9; + const startMinute = parseInt(fragment.slice(10, 12)) || 0; + + const generateTimeSlots = (start: number): string[] => { + const slots = []; + for (let i = 0; i < PLAYBACK_HOURS * 6; i++) { + const minutes = (start + i * 10) % 60; + const hours = (startHour + Math.floor((start + i * 10) / 60)) % 24; + slots.push(`${String(hours).padStart(2, "0")}${String(minutes).padStart(2, "0")}`); + } + return slots; + }; + + const timeSlots = generateTimeSlots(startMinute); + const paths = timeSlots.map(slot => `imgs/${date}/${slot}/280.png`); + setImages(paths); }; -- cgit v1.3.1