Compare commits
2 Commits
fe9a985466
...
0ada5c4735
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ada5c4735 | |||
| 3bb87e2806 |
@ -38,12 +38,12 @@ const mapContainerStyle = {
|
|||||||
|
|
||||||
const defaultCenter = { lat: 12.9716, lng: 77.5946 };
|
const defaultCenter = { lat: 12.9716, lng: 77.5946 };
|
||||||
|
|
||||||
export function DailyLogMap({
|
export function DailyLogMap({
|
||||||
latitude,
|
latitude,
|
||||||
longitude,
|
longitude,
|
||||||
showStoreList = false
|
showStoreList = false
|
||||||
}: {
|
}: {
|
||||||
latitude?: number | string | null;
|
latitude?: number | string | null;
|
||||||
longitude?: number | string | null;
|
longitude?: number | string | null;
|
||||||
showStoreList?: boolean;
|
showStoreList?: boolean;
|
||||||
}) {
|
}) {
|
||||||
@ -90,13 +90,13 @@ export function DailyLogMap({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// If coords provided in props, use them
|
// If coords provided in props, use them
|
||||||
if (latitude && longitude && String(latitude).trim() !== '—' && String(longitude).trim() !== '—') {
|
if (latitude && longitude && String(latitude).trim() !== '—' && String(longitude).trim() !== '—') {
|
||||||
const lat = Number(latitude);
|
const lat = Number(latitude);
|
||||||
const lng = Number(longitude);
|
const lng = Number(longitude);
|
||||||
if (!isNaN(lat) && !isNaN(lng)) {
|
if (!isNaN(lat) && !isNaN(lng)) {
|
||||||
setUserLocation({ lat, lng });
|
setUserLocation({ lat, lng });
|
||||||
fetchNearestStores(lat, lng);
|
fetchNearestStores(lat, lng);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise fallback to whatever tactic used for mobile
|
// Otherwise fallback to whatever tactic used for mobile
|
||||||
@ -125,12 +125,12 @@ export function DailyLogMap({
|
|||||||
const bounds = new window.google.maps.LatLngBounds();
|
const bounds = new window.google.maps.LatLngBounds();
|
||||||
bounds.extend(userLocation);
|
bounds.extend(userLocation);
|
||||||
map.fitBounds(bounds);
|
map.fitBounds(bounds);
|
||||||
|
|
||||||
const listener = window.google.maps.event.addListener(map, 'idle', () => {
|
const listener = window.google.maps.event.addListener(map, 'idle', () => {
|
||||||
if (map.getZoom()! > 15) {
|
if (map.getZoom()! > 15) {
|
||||||
map.setZoom(15);
|
map.setZoom(15);
|
||||||
}
|
}
|
||||||
window.google.maps.event.removeListener(listener);
|
window.google.maps.event.removeListener(listener);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [userLocation]);
|
}, [userLocation]);
|
||||||
@ -232,24 +232,24 @@ export function DailyLogMap({
|
|||||||
|
|
||||||
{showStoreList && (
|
{showStoreList && (
|
||||||
<div className="mt-4 p-5 flex flex-col gap-4 bg-[var(--tiles-card-bg)] rounded-xl border border-slate-200">
|
<div className="mt-4 p-5 flex flex-col gap-4 bg-[var(--tiles-card-bg)] rounded-xl border border-slate-200">
|
||||||
<h3 className="font-bold text-slate-800 text-sm m-0 flex items-center gap-2 uppercase tracking-wider">
|
<h3 className="font-bold text-slate-800 text-sm m-0 flex items-center gap-2 uppercase tracking-wider">
|
||||||
<MapPin size={16} className="text-slate-500" /> Nearby Stores
|
<MapPin size={16} className="text-slate-500" /> Nearby Stores
|
||||||
</h3>
|
</h3>
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
{stores.length > 0 ? (
|
{stores.length > 0 ? (
|
||||||
stores.map((store) => (
|
stores.map((store) => (
|
||||||
<div key={store.store_code} className="flex flex-col p-3 rounded-lg border border-slate-100 bg-slate-50 hover:bg-slate-100 transition-colors cursor-pointer" onClick={() => setSelectedStore(store)}>
|
<div key={store.store_code} className="flex flex-col p-3 rounded-lg border border-slate-100 bg-slate-50 hover:bg-slate-100 transition-colors cursor-pointer" onClick={() => setSelectedStore(store)}>
|
||||||
<span className="font-bold text-slate-800 text-sm">{store.business_name}</span>
|
<span className="font-bold text-slate-800 text-sm">{store.business_name}</span>
|
||||||
<span className="text-xs text-slate-500">{store.store_code}</span>
|
<span className="text-xs text-slate-500">{store.store_code}</span>
|
||||||
{store.distance_km != null && (
|
{store.distance_km != null && (
|
||||||
<span className="text-xs text-[#1b37a5] font-semibold mt-1">{store.distance_km.toFixed(2)} km away</span>
|
<span className="text-xs text-[#1b37a5] font-semibold mt-1">{store.distance_km.toFixed(2)} km away</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<span className="text-sm text-slate-400 italic">No nearby stores found.</span>
|
<span className="text-sm text-slate-400 italic">No nearby stores found.</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user