mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
feat(collections): list+map default, map-only toggle, deselect + tooltip fixes (#1081)
- Drop the grid/tile view. The list view is now the default and, on wide screens, a list + persistent map split; a top-left control on the map collapses the list to a full-width map (and back), animating smoothly (the map stays mounted and is nudged to re-layout during the transition). The place search moves onto the map (top-right); mobile keeps a list/map toggle. - Let a place be deselected again: clicking it once more, clicking the map background, or picking another all toggle the selection (collections map now wires onMapClick). - Fix the stuck hover tooltip: selecting a place swaps its marker's DOM node so the browser never fires mouseout/mouseleave, orphaning the fixed-position tooltip (it hung on screen and drifted with scroll). Both map stacks now clear the hover on selection change and on scroll. - Remove CollectionGrid + PlaceCover; add hero eyebrow + map control strings.
This commit is contained in:
@@ -470,8 +470,22 @@ export const MapView = memo(function MapView({
|
||||
|
||||
const handleMarkerHoverOut = useCallback(() => {
|
||||
setHoveredPlace(null)
|
||||
setTooltipPos(null)
|
||||
}, [])
|
||||
|
||||
// A marker's DOM node is replaced when it becomes selected (its icon grows
|
||||
// 36→44px, and the cluster group re-adds it), so the browser never fires
|
||||
// mouseout on the old node and the fixed-position hover tooltip gets orphaned
|
||||
// — it hangs on screen and drifts with page scroll. Drop it on any selection
|
||||
// change and on any scroll so it can never get stuck.
|
||||
useEffect(() => { setHoveredPlace(null); setTooltipPos(null) }, [selectedPlaceId])
|
||||
useEffect(() => {
|
||||
if (!hoveredPlace) return
|
||||
const clear = () => { setHoveredPlace(null); setTooltipPos(null) }
|
||||
window.addEventListener('scroll', clear, true)
|
||||
return () => window.removeEventListener('scroll', clear, true)
|
||||
}, [hoveredPlace])
|
||||
|
||||
const handleMarkerClick = useCallback((id: number) => {
|
||||
onMarkerClick?.(id)
|
||||
}, [onMarkerClick])
|
||||
|
||||
@@ -224,6 +224,18 @@ export function MapViewGL({
|
||||
const [hoverPlace, setHoverPlace] = useState<(Place & { category_color?: string | null; category_icon?: string | null; category_name?: string | null }) | null>(null)
|
||||
const [hoverPos, setHoverPos] = useState<{ x: number; y: number } | null>(null)
|
||||
const hoverIdRef = useRef<number | null>(null)
|
||||
|
||||
// Selecting a place rebuilds its marker element, so the browser never fires
|
||||
// mouseleave on the removed node and the fixed-position hover card gets
|
||||
// orphaned (it stays put and drifts with page scroll). Clear it on selection
|
||||
// change and on any scroll so it can't get stuck.
|
||||
useEffect(() => { hoverIdRef.current = null; setHoverPlace(null); setHoverPos(null) }, [selectedPlaceId])
|
||||
useEffect(() => {
|
||||
if (!hoverPlace) return
|
||||
const clear = () => { hoverIdRef.current = null; setHoverPlace(null); setHoverPos(null) }
|
||||
window.addEventListener('scroll', clear, true)
|
||||
return () => window.removeEventListener('scroll', clear, true)
|
||||
}, [hoverPlace])
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const mapRef = useRef<any | null>(null)
|
||||
|
||||
Reference in New Issue
Block a user