diff --git a/src/features/map/ui/gas-station-map.tsx b/src/features/map/ui/gas-station-map.tsx index 8de342c..45a99df 100644 --- a/src/features/map/ui/gas-station-map.tsx +++ b/src/features/map/ui/gas-station-map.tsx @@ -56,7 +56,7 @@ interface StationListPanelProps { selectedStation: number | null; activeFilters: string[]; activeCities: string[]; - setSelectedStation: (id: number | null) => void; + handleMapStationClick: (id: number) => void; filterToFieldMap: { [key: string]: keyof Stations[number] }; allFilters: string[]; resetFilters: () => void; @@ -205,7 +205,7 @@ function StationListPanel({ selectedStation, activeFilters, activeCities, - setSelectedStation, + handleMapStationClick, filterToFieldMap, allFilters, resetCities, @@ -275,7 +275,7 @@ function StationListPanel({ ? 'border-blue-500 bg-blue-50' : 'border-gray-200 hover:bg-gray-50' }`} - onClick={() => setSelectedStation(station.id)} + onClick={() => handleMapStationClick(station.id)} >

{station.name}

@@ -365,6 +365,11 @@ export default function GasStationMap({ stations }: GasStationMapProps) { const [isStationListOpen, setIsStationListOpen] = useState(false); const [activeFilterTab, setActiveFilterTab] = useState('cities'); + useEffect(() => { + if (selectedStation === null) return; + setIsStationListOpen(true); + }, [selectedStation]); + // Все доступные фильтры const allFilters = [ // 'ДТ', -> нет значения в интерфейсе - TODO: поправить @@ -434,6 +439,16 @@ export default function GasStationMap({ stations }: GasStationMapProps) { [filteredStations], ); + const handleMapStationClick = (stationId: number) => { + setSelectedStation(() => { + if (selectedStation !== null && selectedStation === stationId) { + return null; + } + + return stationId; + }); + }; + // Переключение фильтра услуг const toggleFilter = (filter: string) => { setActiveFilters((prev) => @@ -494,7 +509,7 @@ export default function GasStationMap({ stations }: GasStationMapProps) { selectedStation={selectedStation} activeFilters={activeFilters} activeCities={activeCities} - setSelectedStation={setSelectedStation} + handleMapStationClick={handleMapStationClick} filterToFieldMap={filterToFieldMap} allFilters={allFilters} resetFilters={resetFilters} @@ -506,7 +521,7 @@ export default function GasStationMap({ stations }: GasStationMapProps) {
diff --git a/src/features/map/ui/yandex-map.tsx b/src/features/map/ui/yandex-map.tsx index 590f0f5..d36aeca 100644 --- a/src/features/map/ui/yandex-map.tsx +++ b/src/features/map/ui/yandex-map.tsx @@ -7,7 +7,7 @@ import { Point } from '../model'; type YandexMapProps = { points: Point[]; selectedStation: number | null; - setSelectedStation: Dispatch>; + handleMapStationClick: (id: number) => void; }; const mapCenter = [38.53575, 68.77905]; @@ -15,7 +15,7 @@ const mapCenter = [38.53575, 68.77905]; export const YandexMap = ({ points, selectedStation, - setSelectedStation, + handleMapStationClick, }: YandexMapProps) => { return ( - {points.map((point) => ( - - setSelectedStation(() => { - if (selectedStation !== null && selectedStation === point.id) { - return null; - } - - return point.id; - }) - } - /> - ))} + {points.map((point) => { + const isSelectedStation = selectedStation === point.id; + return ( + handleMapStationClick(point.id)} + /> + ); + })} );