Skip to content

Commit 759a5b8

Browse files
committed
Revert popup size consistency changes to resolve prod issue (hotfix).
1 parent 15e39a4 commit 759a5b8

File tree

2 files changed

+35
-90
lines changed

2 files changed

+35
-90
lines changed

src/components/shared/map/Map.tsx

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { ISeller, ISellerWithSettings } from '@/constants/types';
99
import { fetchSellers } from '@/services/sellerApi';
1010

1111
import MapMarkerPopup from './MapMarkerPopup';
12-
import { CloseButton } from '../Forms/Buttons/Buttons';
1312

1413
import { AppContext } from '../../../../context/AppContextProvider';
1514
import logger from '../../../../logger.config.mjs';
@@ -88,7 +87,6 @@ const Map = ({
8887
const [locationError, setLocationError] = useState(false);
8988
const [isLocationAvailable, setIsLocationAvailable] = useState(false);
9089
const [initialLocationSet, setInitialLocationSet] = useState(false);
91-
const [lastClickedMarker, setLastClickedMarker] = useState<LatLngTuple | null>(null);
9290

9391
useEffect(() => {
9492
if (searchResults.length > 0) {
@@ -134,38 +132,34 @@ const Map = ({
134132
logger.debug('Sellers Array:', { sellers });
135133
}, [sellers]);
136134

137-
useEffect(() => {
138-
if (mapRef.current) {
139-
fetchInitialCoordinates(); // Fetch sellers when map is ready
140-
}
141-
}, [mapRef.current]);
142-
143-
// Function to handle marker click and center popup
135+
// Function to handle marker click
144136
const handleMarkerClick = (sellerCoordinates: LatLngTuple) => {
145137
if (!mapRef.current) return;
146138

147139
const map = mapRef.current;
148-
setLastClickedMarker(sellerCoordinates);
149-
150-
// Set the target zoom level
151-
const targetZoom = 5; // Zoom level when clicking the marker
152-
153-
// Center the map to the marker position without animation
154-
map.setView(sellerCoordinates, targetZoom, { animate: false });
140+
const currentZoom = map.getZoom();
155141

156-
// Calculate offset to center the popup (move right by 2x)
142+
// Set the view to the seller's coordinates
143+
map.setView(sellerCoordinates, currentZoom, { animate: true });
144+
// Get the position of the clicked marker
157145
const markerPoint = map.latLngToContainerPoint(sellerCoordinates);
146+
// Get the width and height of the map container
158147
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);
159152

160-
const centerOffset = L.point(
161-
mapSize.x / 2 - markerPoint.x - 40, // Shift horizontal offset slightly (-40 moves right)
162-
mapSize.y / 2 - markerPoint.y - 229 // Vertical offset unchanged
163-
);
164-
165-
// Pan the map instantly to center the popup without animation
166-
map.panBy(centerOffset, { animate: false });
153+
// Pan the map by the calculated offset
154+
map.panBy(panOffset, { animate: false }); // Disable animation to make the movement instant
167155
};
168156

157+
useEffect(() => {
158+
if (mapRef.current) {
159+
fetchInitialCoordinates(); // Fetch sellers when map is ready
160+
}
161+
}, [mapRef.current]);
162+
169163
const saveMapState = () => {
170164
try{
171165
if (!mapRef.current) {
@@ -383,27 +377,12 @@ const Map = ({
383377
}}
384378
>
385379
<Popup
386-
minWidth={140}
387-
maxWidth={190}
380+
closeButton={true}
381+
minWidth={200}
382+
maxWidth={250}
388383
className="custom-popup"
389-
offset={L.point(4, -0.5)} // Shifted offset from [0, -3] to [10, -3] to move the popup right
384+
offset={L.point(0, -3)} // Ensures the popup is slightly lower than the marker
390385
>
391-
<div
392-
style={{
393-
position: 'absolute',
394-
top: '-6px',
395-
right: '-6px',
396-
zIndex: 1000,
397-
}}
398-
>
399-
<CloseButton
400-
onClick={() => {
401-
mapRef.current?.closePopup(); // Close the popup programmatically
402-
}}
403-
aria-label="Close Popup"
404-
/>
405-
</div>
406-
{/* Popup Content */}
407386
<MapMarkerPopup seller={seller} />
408387
</Popup>
409388
</Marker>

src/components/shared/map/MapMarkerPopup.tsx

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useTranslations, useLocale } from 'next-intl';
22
import Image from 'next/image';
33
import Link from 'next/link';
4-
import { useEffect, useRef, useState } from 'react';
54

65
import TrustMeter from '@/components/shared/Review/TrustMeter';
76
import { Button } from '../Forms/Buttons/Buttons';
@@ -11,17 +10,6 @@ import logger from '../../../../logger.config.mjs';
1110
const MapMarkerPopup = ({ seller }: { seller: any }) => {
1211
const t = useTranslations();
1312
const locale = useLocale();
14-
const nameRef = useRef<HTMLHeadingElement>(null);
15-
const [imageHeight, setImageHeight] = useState(100); // Default height
16-
17-
// Dynamically adjust the image height based on name height
18-
useEffect(() => {
19-
if (nameRef.current) {
20-
const nameHeight = nameRef.current.offsetHeight;
21-
// Reduce image height slightly if name wraps (i.e., height > 22px)
22-
setImageHeight(nameHeight > 22 ? 75 : 100);
23-
}
24-
}, [seller.name]);
2513

2614
const imageUrl =
2715
seller.image && seller.image.trim() !== ''
@@ -45,18 +33,9 @@ const MapMarkerPopup = ({ seller }: { seller: any }) => {
4533

4634
return (
4735
<div style={{ position: 'relative', zIndex: 20, padding: '10px' }}>
48-
{/* Seller name and type */}
36+
{/* Seller name and type - Close with a small gap */}
4937
<div style={{ textAlign: 'center', marginBottom: '5px' }}>
50-
<h2
51-
ref={nameRef}
52-
style={{
53-
fontWeight: 'bold',
54-
fontSize: '18px',
55-
marginBottom: '2px',
56-
lineHeight: '1.2',
57-
overflowWrap: 'break-word', // Ensures long words break properly
58-
}}
59-
>
38+
<h2 style={{ fontWeight: 'bold', fontSize: '18px', marginBottom: '2px' }}>
6039
{seller.name}
6140
</h2>
6241
{seller.seller_type && (
@@ -66,46 +45,33 @@ const MapMarkerPopup = ({ seller }: { seller: any }) => {
6645
)}
6746
</div>
6847

69-
{/* Seller image */}
48+
{/* Seller image - Close to seller type */}
7049
<div style={{ textAlign: 'center', marginBottom: '5px' }}>
7150
<Image
7251
src={imageUrl}
7352
alt="Seller Image"
74-
width={155}
75-
height={135} // Base dimensions
76-
style={{
77-
objectFit: 'cover',
78-
display: 'block',
79-
margin: '0 auto',
80-
maxHeight: `${imageHeight}px`, // Dynamic height based on name length
81-
width: 'auto',
82-
}}
53+
width={150}
54+
height={50}
55+
style={{ borderRadius: '0px', objectFit: 'cover', display: 'block', margin: '0 auto' }}
8356
/>
8457
</div>
8558

86-
{/* Trust-o-meter Label */}
59+
{/* Trust-o-meter Label - Close to image */}
8760
<p style={{ textAlign: 'center', fontWeight: 'bold', fontSize: '14px', marginBottom: '2px' }}>
8861
Trust-o-meter
8962
</p>
9063

91-
{/* Trust-o-meter */}
92-
<div
93-
style={{
94-
display: 'flex',
95-
flexDirection: 'column',
96-
alignItems: 'center',
97-
width: '150px',
98-
margin: '0 auto',
99-
marginBottom: '8px',
100-
}}
101-
>
102-
<TrustMeter ratings={seller.trust_meter_rating} />
64+
{/* Trust-o-meter - Close to the Trust-o-meter label */}
65+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', marginBottom: '8px' }}>
66+
<TrustMeter
67+
ratings={seller.trust_meter_rating}
68+
/>
10369
</div>
10470

10571
{/* Link to Buy button */}
10672
<div style={{ display: 'flex', justifyContent: 'center', marginTop: '5px' }}>
10773
<Link
108-
href={`/${locale}/seller/sale-items/${seller.seller_id}`}
74+
href={`/${locale}/seller/sale-items/${seller.seller_id}`} // Update to your target link
10975
style={{ display: 'flex', justifyContent: 'center', width: '100%' }}
11076
>
11177
<Button

0 commit comments

Comments
 (0)