diff --git a/public/map/oriyo-inactive-marker.png b/public/map/oriyo-inactive-marker.png new file mode 100644 index 0000000..28ec21a Binary files /dev/null and b/public/map/oriyo-inactive-marker.png differ diff --git a/src/features/map/ui/gas-station-map.tsx b/src/features/map/ui/gas-station-map.tsx index 6bfa874..8de342c 100644 --- a/src/features/map/ui/gas-station-map.tsx +++ b/src/features/map/ui/gas-station-map.tsx @@ -8,7 +8,7 @@ import { List, MapPin, } from 'lucide-react'; -import { useMemo, useState } from 'react'; +import { useEffect, useMemo, useRef, useState } from 'react'; import { Stations } from '@/app/api-utlities/@types'; @@ -46,7 +46,6 @@ interface FilterPanelProps { setActiveFilterTab: (tab: string) => void; resetFilters: () => void; resetCities: () => void; - t: (key: string) => string; } // Пропсы для панели списка станций @@ -58,7 +57,6 @@ interface StationListPanelProps { activeFilters: string[]; activeCities: string[]; setSelectedStation: (id: number | null) => void; - t: (key: string) => string; filterToFieldMap: { [key: string]: keyof Stations[number] }; allFilters: string[]; resetFilters: () => void; @@ -80,8 +78,9 @@ function FilterPanel({ setActiveFilterTab, resetFilters, resetCities, - t, }: FilterPanelProps) { + const { t } = useTextController(); + return (
(null); + + useEffect(() => { + if (!selectedStation || !scrollContainerRef.current) return; + + const selectedStationItem = document.getElementById( + `station_${selectedStation}`, + ); + + if (selectedStationItem) { + const container = scrollContainerRef.current; + const itemRect = selectedStationItem.getBoundingClientRect(); + const containerRect = container.getBoundingClientRect(); + + // Calculate the item's position relative to the container + const itemTopRelativeToContainer = + itemRect.top - containerRect.top + container.scrollTop - 10; + + // Scroll the container to bring the item into view + container.scrollTo({ + top: itemTopRelativeToContainer, + behavior: 'smooth', + }); + } + }, [selectedStation]); + return (
{stations.length}
-
+
{stations.length > 0 ? (
{stations.map((station) => { @@ -240,6 +269,7 @@ function StationListPanel({ return (
{/* Station list panel */} @@ -466,7 +495,6 @@ export default function GasStationMap({ stations }: GasStationMapProps) { activeFilters={activeFilters} activeCities={activeCities} setSelectedStation={setSelectedStation} - t={t} filterToFieldMap={filterToFieldMap} allFilters={allFilters} resetFilters={resetFilters} @@ -475,7 +503,11 @@ export default function GasStationMap({ stations }: GasStationMapProps) { {/* Map */}
- +
{/* Control buttons */} diff --git a/src/features/map/ui/yandex-map.tsx b/src/features/map/ui/yandex-map.tsx index 93b667a..c735b9d 100644 --- a/src/features/map/ui/yandex-map.tsx +++ b/src/features/map/ui/yandex-map.tsx @@ -1,17 +1,21 @@ -'use client'; - import { Map, Placemark, YMaps } from '@pbe/react-yandex-maps'; -import React from 'react'; +import React, { Dispatch, SetStateAction } from 'react'; import { Point } from '../model'; type YandexMapProps = { points: Point[]; + selectedStation: number | null; + setSelectedStation: Dispatch>; }; const mapCenter = [55.751574, 37.573856]; -export const YandexMap = ({ points }: YandexMapProps) => { +export const YandexMap = ({ + points, + selectedStation, + setSelectedStation, +}: YandexMapProps) => { return ( { > { geometry={point.coordinates} options={{ iconLayout: 'default#image', - iconImageHref: '/map/oriyo-marker.png', - iconImageSize: [64, 64], + iconImageHref: + !selectedStation || selectedStation === point.id + ? '/map/oriyo-marker.png' + : '/map/oriyo-inactive-marker.png', + iconImageSize: selectedStation === point.id ? [70, 70] : [64, 64], iconImageOffset: [-24, -36], }} + onClick={() => + setSelectedStation(() => { + if (selectedStation !== null && selectedStation === point.id) { + return null; + } + + return point.id; + }) + } /> ))}