mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 18:04:18 +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:
@@ -1,78 +0,0 @@
|
||||
import React from 'react'
|
||||
import { Check, MapPin } from 'lucide-react'
|
||||
import type { CollectionPlace, CollectionStatus } from '@trek/shared'
|
||||
import type { TranslationFn } from '../../types'
|
||||
import PlaceCover from '../shared/PlaceCover'
|
||||
import StatusBadge from './StatusBadge'
|
||||
|
||||
interface CollectionGridProps {
|
||||
places: CollectionPlace[]
|
||||
selectedPlaceId: number | null
|
||||
selectMode: boolean
|
||||
selectedIds: number[]
|
||||
onOpenPlace: (id: number) => void
|
||||
onStatusChange: (placeId: number, status: CollectionStatus) => void
|
||||
onToggleSelect: (id: number) => void
|
||||
t: TranslationFn
|
||||
}
|
||||
|
||||
/**
|
||||
* Grid view — gradient/photo cover cards modelled on the dashboard trip cards.
|
||||
* The place name sits over the cover with a scrim; the status pill (top-right)
|
||||
* cycles idea→want→visited on tap; a compact body carries the category. In
|
||||
* select mode a tap toggles the checkbox instead of opening the place.
|
||||
*/
|
||||
export default function CollectionGrid({
|
||||
places, selectedPlaceId, selectMode, selectedIds, onOpenPlace, onStatusChange, onToggleSelect, t,
|
||||
}: CollectionGridProps): React.ReactElement {
|
||||
return (
|
||||
<div className="col-grid">
|
||||
{places.map(place => {
|
||||
const selected = selectedIds.includes(place.id)
|
||||
const active = selectedPlaceId === place.id
|
||||
const sub = place.category?.name || place.address
|
||||
const activate = () => (selectMode ? onToggleSelect(place.id) : onOpenPlace(place.id))
|
||||
return (
|
||||
<div
|
||||
key={place.id}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={place.name}
|
||||
onClick={activate}
|
||||
onKeyDown={e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); activate() } }}
|
||||
className={`col-card${active || selected ? ' sel' : ''}`}
|
||||
>
|
||||
<div className="col-cover">
|
||||
<PlaceCover place={place} />
|
||||
{selectMode && (
|
||||
<span className={`col-card-check${selected ? ' on' : ''}`}>
|
||||
{selected && <Check size={14} strokeWidth={3} />}
|
||||
</span>
|
||||
)}
|
||||
<span className="col-card-status">
|
||||
<StatusBadge
|
||||
status={place.status}
|
||||
showLabel={false}
|
||||
onCover
|
||||
onChange={selectMode ? undefined : next => onStatusChange(place.id, next)}
|
||||
t={t}
|
||||
/>
|
||||
</span>
|
||||
<span className="col-card-name">{place.name}</span>
|
||||
</div>
|
||||
{sub && (
|
||||
<div className="col-card-body">
|
||||
<span className="col-card-cat">
|
||||
{place.category?.name
|
||||
? <span className="cdot" style={{ background: place.category.color || '#6366f1' }} />
|
||||
: <MapPin size={13} />}
|
||||
<span>{sub}</span>
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -7,6 +7,8 @@ interface CollectionMapProps {
|
||||
places: CollectionPlace[]
|
||||
selectedPlaceId: number | null
|
||||
onOpenPlace: (id: number) => void
|
||||
/** Clicking the map background clears the selection. */
|
||||
onDeselect?: () => void
|
||||
dark: boolean
|
||||
}
|
||||
|
||||
@@ -16,7 +18,7 @@ interface CollectionMapProps {
|
||||
* The parent `.col-mapwrap` supplies the rounded, bordered box + height, so this
|
||||
* just fills it.
|
||||
*/
|
||||
export default function CollectionMap({ places, selectedPlaceId, onOpenPlace, dark }: CollectionMapProps): React.ReactElement {
|
||||
export default function CollectionMap({ places, selectedPlaceId, onOpenPlace, onDeselect, dark }: CollectionMapProps): React.ReactElement {
|
||||
const pts = mappablePlaces(places)
|
||||
const center: [number, number] = pts.length > 0
|
||||
? [pts[0].lat as number, pts[0].lng as number]
|
||||
@@ -31,6 +33,7 @@ export default function CollectionMap({ places, selectedPlaceId, onOpenPlace, da
|
||||
places={pts}
|
||||
selectedPlaceId={selectedPlaceId}
|
||||
onMarkerClick={onOpenPlace}
|
||||
onMapClick={onDeselect ? () => onDeselect() : undefined}
|
||||
center={center}
|
||||
zoom={pts.length > 0 ? 6 : 3}
|
||||
tileUrl={tileUrl}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import React from 'react'
|
||||
import { PanelLeftClose, PanelLeftOpen, Search } from 'lucide-react'
|
||||
import type { CollectionPlace } from '@trek/shared'
|
||||
import type { TranslationFn } from '../../types'
|
||||
import CollectionMap from './CollectionMap'
|
||||
|
||||
interface CollectionMapPanelProps {
|
||||
places: CollectionPlace[]
|
||||
selectedPlaceId: number | null
|
||||
onSelect: (id: number) => void
|
||||
onDeselect: () => void
|
||||
dark: boolean
|
||||
/** Render the floating map controls (desktop). Mobile drives view from the toolbar. */
|
||||
overlay: boolean
|
||||
/** 'list' = split (map can be expanded); 'map' = full (list collapsed). */
|
||||
view: 'list' | 'map'
|
||||
onToggleView: () => void
|
||||
search: string
|
||||
onSearch: (v: string) => void
|
||||
t: TranslationFn
|
||||
}
|
||||
|
||||
/**
|
||||
* The map surface for the collections page — the map plus its floating controls:
|
||||
* a top-left toggle that collapses/expands the list (animating the split) and a
|
||||
* top-right search box. Used both in the desktop split and full-map view.
|
||||
*/
|
||||
export default function CollectionMapPanel({
|
||||
places, selectedPlaceId, onSelect, onDeselect, dark, overlay, view, onToggleView, search, onSearch, t,
|
||||
}: CollectionMapPanelProps): React.ReactElement {
|
||||
return (
|
||||
<div className="col-map-shell">
|
||||
<CollectionMap
|
||||
places={places}
|
||||
selectedPlaceId={selectedPlaceId}
|
||||
onOpenPlace={onSelect}
|
||||
onDeselect={onDeselect}
|
||||
dark={dark}
|
||||
/>
|
||||
{overlay && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggleView}
|
||||
className="col-map-toggle"
|
||||
aria-label={view === 'map' ? t('collections.showList') : t('collections.expandMap')}
|
||||
title={view === 'map' ? t('collections.showList') : t('collections.expandMap')}
|
||||
>
|
||||
{view === 'map' ? <PanelLeftOpen size={17} /> : <PanelLeftClose size={17} />}
|
||||
</button>
|
||||
<div className="col-map-search">
|
||||
<Search size={15} />
|
||||
<input value={search} onChange={e => onSearch(e.target.value)} placeholder={t('collections.search')} />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import { getCached, isLoading, fetchPhoto, onThumbReady } from '../../services/photoService'
|
||||
import { useAuthStore } from '../../store/authStore'
|
||||
import { entityGradient } from '../../utils/gradients'
|
||||
import type { Place } from '../../types'
|
||||
|
||||
interface PlaceCoverProps {
|
||||
place: Pick<Place, 'id' | 'name' | 'image_url' | 'google_place_id' | 'osm_id' | 'lat' | 'lng'>
|
||||
}
|
||||
|
||||
/**
|
||||
* Full-bleed rectangular cover for a place card — the same photoService-backed
|
||||
* lazy fetch as PlaceAvatar, but rendered edge-to-edge (object-fit: cover)
|
||||
* instead of a circle. When there is no photo it falls back to a deterministic
|
||||
* vibrant gradient (entityGradient), matching the dashboard trip cards. The
|
||||
* parent supplies the aspect box + rounding via `.col-cover`.
|
||||
*/
|
||||
export default React.memo(function PlaceCover({ place }: PlaceCoverProps) {
|
||||
const [photoSrc, setPhotoSrc] = useState<string | null>(place.image_url || null)
|
||||
const [visible, setVisible] = useState(false)
|
||||
const imageUrlFailed = useRef(false)
|
||||
const ref = useRef<HTMLDivElement>(null)
|
||||
const placesPhotosEnabled = useAuthStore(s => s.placesPhotosEnabled)
|
||||
|
||||
// Fetch the photo only once the card scrolls near the viewport (or if it is
|
||||
// already cached / carries an image_url), so a long grid stays cheap.
|
||||
useEffect(() => {
|
||||
if (place.image_url) { setVisible(true); return }
|
||||
if (!placesPhotosEnabled) return
|
||||
const el = ref.current
|
||||
if (!el) return
|
||||
const photoId = place.google_place_id || place.osm_id
|
||||
const cacheKey = photoId || `${place.lat},${place.lng}`
|
||||
if (cacheKey && getCached(cacheKey)) { setVisible(true); return }
|
||||
|
||||
const io = new IntersectionObserver(([e]) => { if (e.isIntersecting) { setVisible(true); io.disconnect() } }, { rootMargin: '250px' })
|
||||
io.observe(el)
|
||||
return () => io.disconnect()
|
||||
}, [place.id])
|
||||
|
||||
useEffect(() => {
|
||||
if (!visible) return
|
||||
if (place.image_url) { setPhotoSrc(place.image_url); return }
|
||||
if (!placesPhotosEnabled) return
|
||||
const photoId = place.google_place_id || place.osm_id
|
||||
if (!photoId && !(place.lat && place.lng)) { setPhotoSrc(null); return }
|
||||
|
||||
const cacheKey = photoId || `${place.lat},${place.lng}`
|
||||
const cached = getCached(cacheKey)
|
||||
if (cached) {
|
||||
setPhotoSrc(cached.thumbDataUrl || cached.photoUrl)
|
||||
if (!cached.thumbDataUrl && cached.photoUrl) {
|
||||
return onThumbReady(cacheKey, thumb => setPhotoSrc(thumb))
|
||||
}
|
||||
return
|
||||
}
|
||||
if (isLoading(cacheKey)) {
|
||||
return onThumbReady(cacheKey, thumb => setPhotoSrc(thumb))
|
||||
}
|
||||
fetchPhoto(cacheKey, photoId || `coords:${place.lat}:${place.lng}`, place.lat, place.lng, place.name,
|
||||
entry => { setPhotoSrc(entry.thumbDataUrl || entry.photoUrl) })
|
||||
return onThumbReady(cacheKey, thumb => setPhotoSrc(thumb))
|
||||
}, [visible, place.id, place.image_url, place.google_place_id, place.osm_id])
|
||||
|
||||
if (photoSrc) {
|
||||
return (
|
||||
<div ref={ref} className="col-cover-media">
|
||||
<img
|
||||
src={photoSrc}
|
||||
alt={place.name}
|
||||
decoding="async"
|
||||
loading="lazy"
|
||||
onError={() => {
|
||||
if (!imageUrlFailed.current && photoSrc === place.image_url && (place.google_place_id || place.osm_id)) {
|
||||
imageUrlFailed.current = true
|
||||
const photoId = place.google_place_id || place.osm_id!
|
||||
fetchPhoto(`refetch:${photoId}`, photoId, place.lat ?? undefined, place.lng ?? undefined, place.name,
|
||||
entry => { setPhotoSrc(entry.thumbDataUrl || entry.photoUrl) })
|
||||
} else {
|
||||
setPhotoSrc(null)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return <div ref={ref} className="col-cover-media col-cover-fallback" style={{ backgroundImage: entityGradient(place.id) }} />
|
||||
})
|
||||
Reference in New Issue
Block a user