From ea1670f6e05d22c516d364072b7dde9bf3ebb5ae Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Thu, 1 Sep 2022 11:18:13 +0300 Subject: Extract playback slots to config --- src/Geshem.tsx | 7 ++++--- src/Slider.tsx | 3 ++- src/config.tsx | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Geshem.tsx b/src/Geshem.tsx index 5210622..6e88f19 100644 --- a/src/Geshem.tsx +++ b/src/Geshem.tsx @@ -5,7 +5,7 @@ import { Map } from "./Map"; import { Slider } from "./Slider"; import { DateTime } from "./Datetime"; -import { IMAGES_BASE_URL } from "./config"; +import { IMAGES_BASE_URL, PLAYBACK_HOURS, PLAYBACK_SLOTS } from "./config"; import "./Geshem.css"; import "rc-slider/assets/index.css"; @@ -25,6 +25,7 @@ interface GeshemProps { date?: string } + export function Geshem({ date }: GeshemProps) { const [images, setImages] = useState([]); const [playback] = useState( @@ -32,7 +33,7 @@ export function Geshem({ date }: GeshemProps) { new URL(window.location.toString()).searchParams.get("history") || undefined ); - const [slider, setSlider] = useState(playback ? 143 : 9); + const [slider, setSlider] = useState(playback ? PLAYBACK_SLOTS : 9); useEffect(() => { const fetchImages = async () => @@ -43,7 +44,7 @@ export function Geshem({ date }: GeshemProps) { const buildPlayback = async () => { const date = playback; - const hours = Array.from(Array(24).keys()).map( + const hours = Array.from(Array(PLAYBACK_HOURS).keys()).map( h => `${String(h).padStart(2, "0")}` ); const minutes = Array.from(Array(6).keys()).map( diff --git a/src/Slider.tsx b/src/Slider.tsx index 4d287a2..50223fc 100644 --- a/src/Slider.tsx +++ b/src/Slider.tsx @@ -1,5 +1,6 @@ import React from "react"; import RcSlider, { SliderProps, SliderRef } from 'rc-slider/lib/Slider'; +import { PLAYBACK_SLOTS } from "./config"; // use workaround from: https://github.com/react-component/slider/issues/835#issuecomment-1201805736 const CustomSlider = RcSlider as React.ForwardRefExoticComponent & React.RefAttributes>; @@ -32,7 +33,7 @@ export function Slider({ playback, slider, setSlider }: GeshemSliderProps) {