diff --git a/client/src/components/ui/slider.tsx b/client/src/components/ui/slider.tsx index 6165bced3..c3beec33e 100644 --- a/client/src/components/ui/slider.tsx +++ b/client/src/components/ui/slider.tsx @@ -16,6 +16,7 @@ const Slider = React.forwardRef< + )); Slider.displayName = SliderPrimitive.Root.displayName; diff --git a/client/src/containers/analysis-eudr/map/legend/radd-slider.tsx b/client/src/containers/analysis-eudr/map/legend/radd-slider.tsx index f3ec6f0af..6aeca7ef1 100644 --- a/client/src/containers/analysis-eudr/map/legend/radd-slider.tsx +++ b/client/src/containers/analysis-eudr/map/legend/radd-slider.tsx @@ -1,37 +1,54 @@ +import { useState } from 'react'; import { useDebounce } from 'rooks'; +import { format } from 'date-fns'; import layersData from '../layers.json'; -import { useAppDispatch, useAppSelector } from '@/store/hooks'; +import { useAppDispatch } from '@/store/hooks'; import { setContextualLayer } from '@/store/features/eudr'; import { Slider } from '@/components/ui/slider'; const LAYERD_ID = 'real-time-deforestation-alerts-since-2020-radd'; +const dateFormatter = (date: string) => format(date, 'yyyy MMM dd'); const RADDSlider = () => { const dispatch = useAppDispatch(); - const { contextualLayers } = useAppSelector((state) => state.eudr); + const [values, setValues] = useState([0, 0]); const data = layersData.find((layer) => layer.id === LAYERD_ID); const dates = data?.legend?.dates; - - console.log(contextualLayers); + const handleValueChange = useDebounce((valuesRange) => { + dispatch( + setContextualLayer({ + layer: LAYERD_ID, + configuration: { dateFrom: dates[valuesRange[0]], dateTo: dates[valuesRange[1]] }, + }), + ); + }, 1000); return (
+
+
From
+
+ {dateFormatter(dates[values[0]])} +
+
to
+
+ {dateFormatter(dates[values[1]])} +
+
- dispatch( - setContextualLayer({ - layer: LAYERD_ID, - configuration: { dateFrom: dates[valuesRange[0]], dateTo: dates[valuesRange[1]] }, - }), - ) - } + onValueChange={(values) => { + setValues(values); + handleValueChange(values); + }} + minStepsBetweenThumbs={1} />
{[dates[0], dates[dates.length - 1]].map((year) => (