From a2217cc9ee407c7a7c4dcd05c16c94f0c9ab3355 Mon Sep 17 00:00:00 2001 From: Maxim Velesyuk Date: Sun, 6 Oct 2024 17:08:58 +0200 Subject: [PATCH] Update timelapse elements --- src/pages/map/components/StaticPanel.tsx | 5 +- src/pages/map/components/TesterButton.tsx | 2 +- .../components/timelapse/TimelapseButton.tsx | 151 ++++++++++++++---- 3 files changed, 124 insertions(+), 34 deletions(-) diff --git a/src/pages/map/components/StaticPanel.tsx b/src/pages/map/components/StaticPanel.tsx index 00f9d599..cfa5fb75 100644 --- a/src/pages/map/components/StaticPanel.tsx +++ b/src/pages/map/components/StaticPanel.tsx @@ -40,12 +40,11 @@ export default function StaticPanel({ children }: Props) { return ( + diff --git a/src/pages/map/components/timelapse/TimelapseButton.tsx b/src/pages/map/components/timelapse/TimelapseButton.tsx index 8a425a0f..c28f7a95 100644 --- a/src/pages/map/components/timelapse/TimelapseButton.tsx +++ b/src/pages/map/components/timelapse/TimelapseButton.tsx @@ -6,22 +6,52 @@ import { SliderThumb, } from '@mui/material' import { Mark } from '@mui/material/Slider/useSlider.types' +import { useQuery } from '@tanstack/react-query' import { range } from 'lodash' import { useState } from 'react' +import { fetchMovesByDate } from 'utils/api' import { Color } from 'utils/types' type Props = {} type FormState = 'closed' | 'date' | 'move' -const DateMarks = range(1, 40, 1).map((value) => ({ +const StartDate = new Date('2024-10-01') +const Today = new Date() + +const daysBetween = (date1: Date, date2: Date) => { + const diffTime = Math.abs(date2.getTime() - date1.getTime()) + return Math.abs(diffTime / (1000 * 60 * 60 * 24)) +} + +const AmountOfDays = daysBetween(StartDate, Today) +const StartDateDay = StartDate.getDate() + +const DateMarks = range(0, AmountOfDays, 1).map((value) => ({ value, - label: value.toString(), + label: (value + StartDateDay).toString(), })) export default function TimelapseButton() { const [formState, setFormState] = useState('closed') - const [date, setDate] = useState(1) + const [dateDiff, setDateDiff] = useState(1) + const [moveId, setMoveId] = useState(1) + + const currentDate = new Date(StartDate) + currentDate.setDate(StartDate.getDate() + dateDiff) + + const dateString = currentDate.toLocaleDateString('ru-RU', { + day: 'numeric', + month: 'long', + }) + + const datePart = currentDate.toISOString().split('T')[0] + + const { data: movesByDay } = useQuery({ + queryKey: ['timelapse', dateDiff], + queryFn: () => fetchMovesByDate(datePart), + staleTime: 1000 * 60 * 5, + }) if (formState === 'closed') { return ( @@ -49,8 +79,8 @@ export default function TimelapseButton() { }} > setDate(value as number)} + value={dateDiff} + onChange={(_, value) => setDateDiff(Math.floor(value as number))} /> - + @@ -84,6 +118,25 @@ export default function TimelapseButton() { ) } + const turnMarks = range(0, 20, 1).map((value) => ({ + value, + label: (value + 1).toString(), + })) + + const nextDay = new Date(currentDate) + nextDay.setDate(currentDate.getDate() + 1) + const nextDayString = nextDay.toLocaleDateString('ru-RU', { + day: 'numeric', + month: 'long', + }) + + const prevDay = new Date(currentDate) + prevDay.setDate(currentDate.getDate() - 1) + const prevDayString = prevDay.toLocaleDateString('ru-RU', { + day: 'numeric', + month: 'long', + }) + return ( setDate(value as number)} + value={moveId} + onChange={(_, value) => { + setMoveId(Math.floor(value as number)) + }} /> - - + + {!datesEqual(currentDate, StartDate) ? ( + + ) : ( + + )} - + {!datesEqual(currentDate, Today) ? ( + + ) : ( + + )} ) @@ -185,7 +265,7 @@ function CustomRail(props: any) { position: 'absolute', height: '4px', top: '10px', - width: '100%', + width: '1265px', backgroundColor: Color.blue, borderRadius: '5px', }} @@ -195,17 +275,28 @@ function CustomRail(props: any) { function CustomThumb(props: any) { // return + // console.log(props) + const className = props.className as string + const isActive = className.includes('Mui-active') + return ( ) } + +function datesEqual(date1: Date, date2: Date) { + const date1String = date1.toISOString().slice(0, 10) + const date2String = date2.toISOString().slice(0, 10) + return date1String === date2String +}