Skip to content

Commit 9768fa6

Browse files
authored
Merge pull request #384 from map-of-pi/dev
Approved for deployment.
2 parents 5a19827 + b4cfbc6 commit 9768fa6

File tree

4 files changed

+68
-29
lines changed

4 files changed

+68
-29
lines changed

src/app/[locale]/seller/sale-items/[id]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export default function BuyFromSellerForm({ params }: { params: { id: string } }
174174
alt="seller logo"
175175
fill
176176
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
177-
style={{ objectFit: 'cover', maxHeight: '200px', maxWidth: '100%' }}
177+
style={{ objectFit: 'contain', maxHeight: '200px', maxWidth: '100%' }}
178178
/>
179179
</div>
180180
<div className="my-auto">

src/components/shared/About/Info/Info.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { CloseButton } from '@/components/shared/Forms/Buttons/Buttons';
1313
const InfoModel = (props: any) => {
1414
const t = useTranslations();
1515

16-
const [version, setVersion] = useState('v1.4.0');
16+
const [version, setVersion] = useState('v1.5.6');
1717

1818
return (
1919
<>

src/components/shared/map/Map.tsx

+42-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useTranslations } from 'next-intl';
22
import Image from 'next/image';
3-
import React, { useEffect, useState, useCallback, useContext } from 'react';
3+
import React, { useEffect, useState, useCallback, useContext, useRef } from 'react';
44
import { MapContainer, Marker, Popup, TileLayer, useMapEvents } from 'react-leaflet';
55
import L, { LatLngExpression, LatLngBounds, LatLngTuple } from 'leaflet';
66
import _ from 'lodash';
@@ -132,34 +132,54 @@ const Map = ({
132132
logger.debug('Sellers Array:', { sellers });
133133
}, [sellers]);
134134

135-
// Function to handle marker click
136-
const handleMarkerClick = (sellerCoordinates: LatLngTuple) => {
137-
if (!mapRef.current) return;
138-
139-
const map = mapRef.current;
140-
const currentZoom = map.getZoom();
141-
142-
// Set the view to the seller's coordinates
143-
map.setView(sellerCoordinates, currentZoom, { animate: true });
144-
// Get the position of the clicked marker
145-
const markerPoint = map.latLngToContainerPoint(sellerCoordinates);
146-
// Get the width and height of the map container
147-
const mapSize = map.getSize();
148-
const mapWidth = mapSize.x;
149-
const mapHeight = mapSize.y;
150-
// Calculate the offsets to center the marker in the map view
151-
const panOffset = L.point(mapWidth / 2 - markerPoint.x, mapHeight / 2 - markerPoint.y);
152-
153-
// Pan the map by the calculated offset
154-
map.panBy(panOffset, { animate: false }); // Disable animation to make the movement instant
135+
const useMarkerZoomHandler = (mapRef: React.RefObject<L.Map>) => {
136+
const lastClickedMarker = useRef<string | null>(null);
137+
138+
// Function to handle marker click
139+
const handleMarkerClick = (sellerCoordinates: LatLngTuple) => {
140+
if (!mapRef.current) return;
141+
142+
const map = mapRef.current;
143+
const currentZoom = map.getZoom();
144+
const maxZoom = map.getMaxZoom();
145+
146+
const coordKey = sellerCoordinates.join(',');
147+
148+
// Prevent zooming again on the same marker
149+
if (lastClickedMarker.current === coordKey) return;
150+
151+
// Update the last clicked marker
152+
lastClickedMarker.current = coordKey;
153+
154+
// Calculate target zoom
155+
const targetZoom = Math.min(currentZoom + 3, maxZoom);
156+
157+
// Convert lat/lng to pixel position
158+
const markerPoint = map.latLngToContainerPoint(sellerCoordinates);
159+
160+
// Offset to move popup up and left
161+
const OFFSET_X = -3;
162+
const OFFSET_Y = 28;
163+
const panOffset = L.point(OFFSET_X, OFFSET_Y);
164+
165+
// New center for map
166+
const newCenter = map.containerPointToLatLng(markerPoint.subtract(panOffset));
167+
168+
// Zoom and pan with animation
169+
map.setView(newCenter, targetZoom, { animate: true });
170+
};
171+
172+
return handleMarkerClick;
155173
};
156-
174+
157175
useEffect(() => {
158176
if (mapRef.current) {
159177
fetchInitialCoordinates(); // Fetch sellers when map is ready
160178
}
161179
}, [mapRef.current]);
162180

181+
const handleMarkerClick = useMarkerZoomHandler(mapRef);
182+
163183
const saveMapState = () => {
164184
try{
165185
if (!mapRef.current) {

src/components/shared/map/MapMarkerPopup.tsx

+24-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const MapMarkerPopup = ({ seller }: { seller: any }) => {
1616
? seller.image
1717
: '/images/logo.svg';
1818

19+
const truncateChars = (text: string, maxChars: number): string => {
20+
return text.length > maxChars ? text.slice(0, maxChars) + '...' : text;
21+
};
22+
1923
const translateSellerCategory = (category: string): string => {
2024
switch (category) {
2125
case 'activeSeller':
@@ -35,24 +39,39 @@ const MapMarkerPopup = ({ seller }: { seller: any }) => {
3539
<div style={{ position: 'relative', zIndex: 20, padding: '10px' }}>
3640
{/* Seller name and type - Close with a small gap */}
3741
<div style={{ textAlign: 'center', marginBottom: '5px' }}>
38-
<h2 style={{ fontWeight: 'bold', fontSize: '18px', marginBottom: '2px' }}>
39-
{seller.name}
42+
<h2
43+
style={{
44+
fontWeight: 'bold',
45+
fontSize: '15px',
46+
marginBottom: '2px',
47+
whiteSpace: 'nowrap',
48+
overflow: 'hidden',
49+
textOverflow: 'ellipsis',
50+
}}
51+
>
52+
{truncateChars(seller.name, 12)} {/* Adjust limit as needed */}
4053
</h2>
54+
4155
{seller.seller_type && (
4256
<p style={{ fontSize: '14px', color: '#6B7280', marginTop: '0px', marginBottom: '4px' }}>
4357
{translateSellerCategory(seller.seller_type)}
4458
</p>
59+
4560
)}
4661
</div>
4762

4863
{/* Seller image - Close to seller type */}
49-
<div style={{ textAlign: 'center', marginBottom: '5px' }}>
64+
<div style={{ width: '150px', height: '70px', overflow: 'hidden', margin: '0 auto', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
5065
<Image
5166
src={imageUrl}
5267
alt="Seller Image"
5368
width={150}
54-
height={50}
55-
style={{ borderRadius: '0px', objectFit: 'cover', display: 'block', margin: '0 auto' }}
69+
height={70}
70+
style={{
71+
objectFit: 'contain',
72+
width: '100%',
73+
height: '100%',
74+
}}
5675
/>
5776
</div>
5877

0 commit comments

Comments
 (0)