update: open station-list on-marker-click and add unselect opportunity

This commit is contained in:
BunyodL 2025-05-03 02:50:07 +05:00
parent 9fc4b2018e
commit e8bb8a7830
2 changed files with 41 additions and 31 deletions

View File

@ -56,7 +56,7 @@ interface StationListPanelProps {
selectedStation: number | null; selectedStation: number | null;
activeFilters: string[]; activeFilters: string[];
activeCities: string[]; activeCities: string[];
setSelectedStation: (id: number | null) => void; handleMapStationClick: (id: number) => void;
filterToFieldMap: { [key: string]: keyof Stations[number] }; filterToFieldMap: { [key: string]: keyof Stations[number] };
allFilters: string[]; allFilters: string[];
resetFilters: () => void; resetFilters: () => void;
@ -205,7 +205,7 @@ function StationListPanel({
selectedStation, selectedStation,
activeFilters, activeFilters,
activeCities, activeCities,
setSelectedStation, handleMapStationClick,
filterToFieldMap, filterToFieldMap,
allFilters, allFilters,
resetCities, resetCities,
@ -275,7 +275,7 @@ function StationListPanel({
? 'border-blue-500 bg-blue-50' ? 'border-blue-500 bg-blue-50'
: 'border-gray-200 hover:bg-gray-50' : 'border-gray-200 hover:bg-gray-50'
}`} }`}
onClick={() => setSelectedStation(station.id)} onClick={() => handleMapStationClick(station.id)}
> >
<div className='flex items-start justify-between'> <div className='flex items-start justify-between'>
<h4 className='font-medium'>{station.name}</h4> <h4 className='font-medium'>{station.name}</h4>
@ -365,6 +365,11 @@ export default function GasStationMap({ stations }: GasStationMapProps) {
const [isStationListOpen, setIsStationListOpen] = useState(false); const [isStationListOpen, setIsStationListOpen] = useState(false);
const [activeFilterTab, setActiveFilterTab] = useState('cities'); const [activeFilterTab, setActiveFilterTab] = useState('cities');
useEffect(() => {
if (selectedStation === null) return;
setIsStationListOpen(true);
}, [selectedStation]);
// Все доступные фильтры // Все доступные фильтры
const allFilters = [ const allFilters = [
// 'ДТ', -> нет значения в интерфейсе - TODO: поправить // 'ДТ', -> нет значения в интерфейсе - TODO: поправить
@ -434,6 +439,16 @@ export default function GasStationMap({ stations }: GasStationMapProps) {
[filteredStations], [filteredStations],
); );
const handleMapStationClick = (stationId: number) => {
setSelectedStation(() => {
if (selectedStation !== null && selectedStation === stationId) {
return null;
}
return stationId;
});
};
// Переключение фильтра услуг // Переключение фильтра услуг
const toggleFilter = (filter: string) => { const toggleFilter = (filter: string) => {
setActiveFilters((prev) => setActiveFilters((prev) =>
@ -494,7 +509,7 @@ export default function GasStationMap({ stations }: GasStationMapProps) {
selectedStation={selectedStation} selectedStation={selectedStation}
activeFilters={activeFilters} activeFilters={activeFilters}
activeCities={activeCities} activeCities={activeCities}
setSelectedStation={setSelectedStation} handleMapStationClick={handleMapStationClick}
filterToFieldMap={filterToFieldMap} filterToFieldMap={filterToFieldMap}
allFilters={allFilters} allFilters={allFilters}
resetFilters={resetFilters} resetFilters={resetFilters}
@ -506,7 +521,7 @@ export default function GasStationMap({ stations }: GasStationMapProps) {
<YandexMap <YandexMap
points={points} points={points}
selectedStation={selectedStation} selectedStation={selectedStation}
setSelectedStation={setSelectedStation} handleMapStationClick={handleMapStationClick}
/> />
</div> </div>

View File

@ -7,7 +7,7 @@ import { Point } from '../model';
type YandexMapProps = { type YandexMapProps = {
points: Point[]; points: Point[];
selectedStation: number | null; selectedStation: number | null;
setSelectedStation: Dispatch<SetStateAction<number | null>>; handleMapStationClick: (id: number) => void;
}; };
const mapCenter = [38.53575, 68.77905]; const mapCenter = [38.53575, 68.77905];
@ -15,7 +15,7 @@ const mapCenter = [38.53575, 68.77905];
export const YandexMap = ({ export const YandexMap = ({
points, points,
selectedStation, selectedStation,
setSelectedStation, handleMapStationClick,
}: YandexMapProps) => { }: YandexMapProps) => {
return ( return (
<YMaps <YMaps
@ -39,30 +39,25 @@ export const YandexMap = ({
}} }}
className='h-full max-h-[500px] w-full overflow-hidden rounded-md shadow-lg' className='h-full max-h-[500px] w-full overflow-hidden rounded-md shadow-lg'
> >
{points.map((point) => ( {points.map((point) => {
const isSelectedStation = selectedStation === point.id;
return (
<Placemark <Placemark
key={point.id} key={point.id}
geometry={point.coordinates} geometry={point.coordinates}
options={{ options={{
iconLayout: 'default#image', iconLayout: 'default#image',
iconImageHref: iconImageHref:
!selectedStation || selectedStation === point.id !selectedStation || isSelectedStation
? '/map/oriyo-marker.png' ? '/map/oriyo-marker.png'
: '/map/oriyo-inactive-marker.png', : '/map/oriyo-inactive-marker.png',
iconImageSize: selectedStation === point.id ? [70, 70] : [64, 64], iconImageSize: isSelectedStation ? [70, 70] : [64, 64],
iconImageOffset: [-24, -36], iconImageOffset: isSelectedStation ? [-28, -40] : [-24, -36],
}} }}
onClick={() => onClick={() => handleMapStationClick(point.id)}
setSelectedStation(() => {
if (selectedStation !== null && selectedStation === point.id) {
return null;
}
return point.id;
})
}
/> />
))} );
})}
</Map> </Map>
</YMaps> </YMaps>
); );