"use client"; import { useState } from "react"; import type { FeatureCollection } from "geojson"; import { useIsochrones } from "@/hooks/useIsochrones"; type IsoMode = "foot-walking" | "cycling-regular" | "driving-car"; interface Props { cadNum: string; onResult: (fc: FeatureCollection) => void; } const MODE_LABELS: Record = { "foot-walking": "Пешком", "cycling-regular": "Велосипед", "driving-car": "Машина", }; const ALL_TIMES = [10, 15, 30] as const; export function IsochronesPanel({ cadNum, onResult }: Props) { const [mode, setMode] = useState("foot-walking"); const [times, setTimes] = useState>(new Set([10, 15])); const { mutate, isPending, isError, error } = useIsochrones(); function toggleTime(t: number) { setTimes((prev) => { const next = new Set(prev); if (next.has(t)) { next.delete(t); } else { next.add(t); } return next; }); } function handleShow() { const timesMin = ALL_TIMES.filter((t) => times.has(t)); if (timesMin.length === 0) return; mutate( { cadNum, mode, timesMin }, { onSuccess: (res) => { onResult(res.geojson); }, }, ); } return (
Изохроны доступности
{/* Mode radio */}
{(Object.keys(MODE_LABELS) as IsoMode[]).map((m) => ( ))}
{/* Time checkboxes */}
{ALL_TIMES.map((t) => { const checked = times.has(t); return ( ); })}
{/* Show button */} {/* Error */} {isError && (
{error instanceof Error ? error.message : "Ошибка запроса изохрон"}
)}
); }