Skip to content

Commit 2d3d20c

Browse files
committed
iterate
1 parent 4c5dcc3 commit 2d3d20c

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

apps/web/components/DirectoryClient.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,15 @@ export default function DirectoryClient({ coffeeFarms, teaFarms, initialFarmId }
7272
}
7373
}, [])
7474

75-
const farms = tab === 'coffee'
76-
? shuffledCoffee
77-
: tab === 'tea'
78-
? shuffledTea
79-
: [...shuffledCoffee, ...shuffledTea]
80-
8175
const allFarms: AnyFarm[] = useMemo(
8276
() => [...shuffledCoffee, ...shuffledTea],
8377
[shuffledCoffee, shuffledTea]
8478
)
79+
80+
const farms = useMemo(
81+
() => tab === 'coffee' ? shuffledCoffee : tab === 'tea' ? shuffledTea : allFarms,
82+
[tab, shuffledCoffee, shuffledTea, allFarms]
83+
)
8584
const selectedFarm = selectedId ? allFarms.find(f => f.id === selectedId) ?? null : null
8685

8786
const allStates = useMemo(

apps/web/components/FarmMap.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@ const TEA_COLOR = '#15803d' // green
2727
const isCoffee = (farm: AnyFarm) => 'varieties' in farm
2828

2929
const defStyle = (farm: AnyFarm): L.CircleMarkerOptions => ({
30-
radius: 7,
30+
radius: 5,
3131
color: '#fff',
3232
weight: 1.5,
3333
fillColor: isCoffee(farm) ? COFFEE_COLOR : TEA_COLOR,
3434
fillOpacity: 0.85,
3535
className: 'farm-dot',
36+
pane: 'farmDotsPane',
3637
})
3738

3839
const hiStyle = (farm: AnyFarm): L.CircleMarkerOptions => ({
39-
radius: 11,
40+
radius: 8,
4041
color: '#fff',
4142
weight: 2.5,
4243
fillColor: isCoffee(farm) ? COFFEE_COLOR : TEA_COLOR,
4344
fillOpacity: 1,
4445
className: 'farm-dot farm-dot--selected',
46+
pane: 'farmDotsPane',
4547
})
4648

4749
const CYCLOSM_URL = 'https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png'
@@ -58,6 +60,7 @@ export default function FarmMap({ farms, selectedId, selectedFarm, onSelect, onB
5860
const markersRef = useRef<Map<string, { marker: L.CircleMarker; farm: AnyFarm }>>(new Map())
5961
const prevSelectedRef = useRef<string | null>(null)
6062
const overlayRef = useRef<L.Polygon | null>(null)
63+
const userInteractedRef = useRef(false)
6164
const [mapReady, setMapReady] = useState(false)
6265

6366
// Initialise the Leaflet map once
@@ -79,13 +82,15 @@ export default function FarmMap({ farms, selectedId, selectedFarm, onSelect, onB
7982
}).setView([20, 80], 6)
8083

8184
mapRef.current = map
85+
map.createPane('farmDotsPane').style.zIndex = '450'
8286
setMapReady(true)
8387

8488
const emitBounds = () => {
85-
if (!onBoundsChange) return
89+
if (!userInteractedRef.current || !onBoundsChange) return
8690
const b = map.getBounds()
8791
onBoundsChange({ north: b.getNorth(), south: b.getSouth(), east: b.getEast(), west: b.getWest() })
8892
}
93+
map.on('movestart', () => { userInteractedRef.current = true })
8994
map.on('moveend', emitBounds)
9095
map.on('zoomend', emitBounds)
9196

@@ -171,8 +176,8 @@ export default function FarmMap({ farms, selectedId, selectedFarm, onSelect, onB
171176
existing.set(farm.id, { marker, farm })
172177
})
173178

174-
// Only fit bounds when nothing is selected — selecting a farm will flyTo instead
175-
if (!selectedId) {
179+
// Only fit bounds on initial load before the user has panned/zoomed
180+
if (!selectedId && !userInteractedRef.current) {
176181
const coords: [number, number][] = []
177182
existing.forEach(({ marker }, id) => {
178183
if (nextIds.has(id)) coords.push([marker.getLatLng().lat, marker.getLatLng().lng])
@@ -215,8 +220,8 @@ export default function FarmMap({ farms, selectedId, selectedFarm, onSelect, onB
215220
if (lat != null && lng != null) {
216221
map.setView([lat, lng], 13, { animate: false })
217222
}
218-
} else {
219-
// Nothing selected — zoom back out to show all visible markers
223+
} else if (!userInteractedRef.current) {
224+
// Nothing selected and user hasn't manually navigated — zoom to show all markers
220225
const coords: [number, number][] = []
221226
markersRef.current.forEach(({ marker }) => {
222227
coords.push([marker.getLatLng().lat, marker.getLatLng().lng])

0 commit comments

Comments
 (0)