diff --git a/src/features/edge-detail/components/ArchiveView.tsx b/src/features/edge-detail/components/ArchiveView.tsx index 79a534d..b080c81 100644 --- a/src/features/edge-detail/components/ArchiveView.tsx +++ b/src/features/edge-detail/components/ArchiveView.tsx @@ -1,5 +1,7 @@ import { useState } from 'react'; -import { CalendarClock, ChevronDown, DatabaseZap, Search } from 'lucide-react'; +import type { RefObject } from 'react'; +import { useRef } from 'react'; +import { CalendarDays, CalendarClock, ChevronDown, Clock3, DatabaseZap, Search } from 'lucide-react'; import type { CurrentItem } from '../../../entities/current/types'; import type { HistoryResponse } from '../../../entities/history/types'; import { HistoryChart } from '../../../features/history-chart/HistoryChart'; @@ -27,6 +29,54 @@ type ArchiveViewProps = { onToggleTag: (tag: string) => void; }; +type RangePart = 'from' | 'to'; +type RangeInputPart = 'date' | 'time'; + +function getRangeInputPart(value: string, part: RangeInputPart): string { + const [date = '', time = ''] = value.split('T'); + return part === 'date' ? date : time; +} + +function updateRangeInputPart(value: string, part: RangeInputPart, nextValue: string): string { + const date = getRangeInputPart(value, 'date'); + const time = getRangeInputPart(value, 'time'); + return part === 'date' ? `${nextValue}T${time}` : `${date}T${nextValue}`; +} + +function openInputPicker(input: HTMLInputElement | null): void { + input?.focus(); + input?.showPicker?.(); +} + +type DateRangeFieldProps = { + icon: 'date' | 'time'; + inputRef: RefObject; + type: 'date' | 'time'; + value: string; + onChange: (value: string) => void; +}; + +function DateRangeField({ icon, inputRef, type, value, onChange }: DateRangeFieldProps) { + const Icon = icon === 'date' ? CalendarDays : Clock3; + const label = icon === 'date' ? 'Открыть календарь' : 'Открыть выбор времени'; + + return ( +
openInputPicker(inputRef.current)}> + + onChange(event.target.value)} + /> +
+ ); +} + export function ArchiveView({ getTagLabel, history, @@ -49,6 +99,16 @@ export function ArchiveView({ const [selectorOpen, setSelectorOpen] = useState(false); const selectedPreview = selectedTags.slice(0, 10); const hiddenSelectedCount = Math.max(0, selectedTags.length - selectedPreview.length); + const fromDateRef = useRef(null); + const fromTimeRef = useRef(null); + const toDateRef = useRef(null); + const toTimeRef = useRef(null); + const updateRangePart = (rangePart: RangePart, inputPart: RangeInputPart, value: string) => { + onRangeChange({ + ...range, + [rangePart]: updateRangeInputPart(range[rangePart], inputPart, value), + }); + }; return (
@@ -148,22 +208,40 @@ export function ArchiveView({ ))} -