feat(collections): redesign the page on the dashboard glass language (#1081)

Rebuilds the /collections page from the functional placeholder into the
dashboard's glass visual language (light + dark):

- A colour-washed hero per list: eyebrow + member avatars, big title, and
  stat chips (All / Idea / Want / Visited) that double as the status filter.
- A sticky glass list rail (owned + shared + invites) with a mobile drawer.
- Gradient/photo cover place cards modelled on the trip cards, via a new
  rectangular PlaceCover (photoService-backed, gradient fallback) + a shared
  gradients util. List and map views restyled to match.
- Status pill rendered as a role=button span so it survives the .trek-dash
  button reset and can nest inside the card; the share member-count badge is
  now owner-only.
- New hero eyebrow strings across all locales.
This commit is contained in:
Maurice
2026-07-01 09:23:12 +02:00
committed by Maurice
parent 5f9da5b72f
commit 4e478722c3
33 changed files with 893 additions and 333 deletions
@@ -1,8 +1,8 @@
import React from 'react'
import { Check } from 'lucide-react'
import { Check, MapPin } from 'lucide-react'
import type { CollectionPlace, CollectionStatus } from '@trek/shared'
import type { TranslationFn } from '../../types'
import PlaceAvatar from '../shared/PlaceAvatar'
import PlaceCover from '../shared/PlaceCover'
import StatusBadge from './StatusBadge'
interface CollectionGridProps {
@@ -17,52 +17,60 @@ interface CollectionGridProps {
}
/**
* Grid view — PlaceAvatar thumb cards (rounded-xl) with the status badge in the
* top-right corner. In select mode a tap toggles the checkbox; otherwise it
* opens the place.
* 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="grid gap-3 [grid-template-columns:repeat(auto-fill,minmax(160px,1fr))]">
<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 (
<button
<div
key={place.id}
type="button"
onClick={() => (selectMode ? onToggleSelect(place.id) : onOpenPlace(place.id))}
className={`group relative flex flex-col rounded-xl border bg-surface-card text-left overflow-hidden transition-all hover:shadow-card hover:-translate-y-0.5 ${active || selected ? 'border-accent ring-1 ring-accent' : 'border-edge'}`}
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' : ''}`}
>
{/* Photo band */}
<div className="relative flex items-center justify-center h-28 bg-surface-secondary">
<PlaceAvatar place={place} size={64} category={place.category ? { color: place.category.color ?? undefined, icon: place.category.icon ?? undefined } : null} />
<div className="absolute top-2 right-2">
<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}
/>
</div>
{selectMode && (
<div className={`absolute top-2 left-2 w-5 h-5 rounded-md flex items-center justify-center border ${selected ? 'bg-accent border-accent' : 'bg-surface-card/90 border-edge'}`}>
{selected && <Check size={13} className="text-accent-text" strokeWidth={3} />}
</div>
)}
</span>
<span className="col-card-name">{place.name}</span>
</div>
{/* Body */}
<div className="flex flex-col gap-0.5 px-3 py-2.5 min-w-0">
<span className="text-[13px] font-semibold text-content truncate">{place.name}</span>
{(place.category?.name || place.address) && (
<span className="text-[11px] text-content-faint truncate">
{place.category?.name || place.address}
{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>
</button>
</div>
)}
</div>
)
})}
</div>
@@ -0,0 +1,114 @@
import React from 'react'
import { Share2, Users, Plus } from 'lucide-react'
import type { CollectionMember } from '@trek/shared'
import type { TranslationFn } from '../../types'
import type { StatusFilter } from '../../store/collectionStore'
import { STATUS_META, STATUS_ORDER } from '../../pages/collections/collectionsModel'
const AV_COLORS = ['#6366f1', '#ec4899', '#14b8a6', '#f97316', '#8b5cf6', '#3b82f6', '#ef4444', '#22c55e']
function initials(name: string): string {
return name.trim().split(/\s+/).slice(0, 2).map(w => w[0]?.toUpperCase() ?? '').join('') || '?'
}
interface CollectionHeroProps {
eyebrow: string
title: string
/** List colour — drives the gradient wash when there is no cover image. */
color: string
coverImage?: string | null
counts: Record<StatusFilter, number>
statusFilter: StatusFilter
onStatusFilter: (f: StatusFilter) => void
/** Accepted members (owner first) — shown as an avatar stack when shared. */
members: CollectionMember[]
canShare: boolean
isOwner: boolean
shareMemberCount: number
onShare: () => void
onNewList: () => void
t: TranslationFn
}
/**
* The page header — a colour-washed (or cover-image) glass hero that gives the
* active list an identity: an eyebrow with the sharing state + member avatars,
* the big list name, and a row of stat chips that double as the status filter
* (All / Idea / Want / Visited with live counts). Share + New-list actions sit
* top-right. Modelled on the dashboard hero-trip.
*/
export default function CollectionHero({
eyebrow, title, color, coverImage, counts, statusFilter, onStatusFilter,
members, canShare, isOwner, shareMemberCount, onShare, onNewList, t,
}: CollectionHeroProps): React.ReactElement {
const accepted = members.filter(m => m.status === 'accepted' || m.is_owner)
const showAvatars = accepted.length > 1
const shown = accepted.slice(0, 5)
const extra = accepted.length - shown.length
const chips: { key: StatusFilter; label: string; color?: string }[] = [
{ key: 'all', label: t('collections.status.filterAll') },
...STATUS_ORDER.map(s => ({ key: s as StatusFilter, label: t(STATUS_META[s].labelKey), color: STATUS_META[s].color })),
]
return (
<header className="col-hero" style={{ ['--hero-color' as string]: color }}>
{coverImage
? <img className="col-hero-img" src={coverImage} alt="" />
: <div className="col-hero-bg" />}
<div className="col-hero-scrim" />
<div className="col-hero-actions">
{canShare && (
<button
type="button"
onClick={onShare}
aria-label={isOwner ? t('collections.share.button') : t('collections.shared')}
title={isOwner ? t('collections.share.button') : t('collections.shared')}
className={`col-glass-btn${isOwner && shareMemberCount > 0 ? ' has-count' : ''}`}
>
{isOwner ? <Share2 size={15} /> : <Users size={15} />}
<span className="txt">{isOwner ? t('collections.share.button') : t('collections.shared')}</span>
{isOwner && shareMemberCount > 0 && <span className="cnt">{shareMemberCount}</span>}
</button>
)}
<button type="button" onClick={onNewList} aria-label={t('collections.newList')} title={t('collections.newList')} className="col-glass-btn">
<Plus size={15} /> <span className="txt">{t('collections.newList')}</span>
</button>
</div>
<div className="col-hero-content">
<div className="col-hero-eyebrow">
<span>{eyebrow}</span>
{showAvatars && (
<span className="members">
{shown.map(m => (
m.avatar
? <img key={m.user_id} className="col-av" src={m.avatar} alt={m.username} />
: <span key={m.user_id} className="col-av" style={{ background: AV_COLORS[m.user_id % AV_COLORS.length] }}>{initials(m.username)}</span>
))}
{extra > 0 && <span className="col-av" style={{ background: 'rgba(255,255,255,.28)' }}>+{extra}</span>}
</span>
)}
</div>
<h1 className="col-hero-title">{title}</h1>
<div className="col-hero-stats">
{chips.map(chip => (
<button
key={chip.key}
type="button"
onClick={() => onStatusFilter(chip.key)}
className={`col-chip${statusFilter === chip.key ? ' on' : ''}`}
>
{chip.color && <span className="sw" style={{ background: chip.color }} />}
{chip.label}
<span className="n">{counts[chip.key]}</span>
</button>
))}
</div>
</div>
</header>
)
}
@@ -17,14 +17,15 @@ interface CollectionListProps {
}
/**
* Dense list view — one row per saved place with a one-tap status cycle on the
* badge. Click the row to open the place (or toggle in select mode).
* List view — one glass row per saved place with a photo avatar, name +
* category/address, and a one-tap status cycle on the badge. Click the row to
* open the place (or toggle it in select mode).
*/
export default function CollectionList({
places, selectedPlaceId, selectMode, selectedIds, onOpenPlace, onStatusChange, onToggleSelect, t,
}: CollectionListProps): React.ReactElement {
return (
<div className="flex flex-col rounded-xl border border-edge bg-surface-card overflow-hidden divide-y divide-edge-faint">
<div className="col-listview">
{places.map(place => {
const selected = selectedIds.includes(place.id)
const active = selectedPlaceId === place.id
@@ -34,25 +35,24 @@ export default function CollectionList({
role="button"
tabIndex={0}
onClick={() => (selectMode ? onToggleSelect(place.id) : onOpenPlace(place.id))}
onKeyDown={e => { if (e.key === 'Enter') onOpenPlace(place.id) }}
className={`flex items-center gap-3 px-3 py-2.5 cursor-pointer transition-colors hover:bg-surface-hover ${active ? 'bg-surface-selected' : ''}`}
onKeyDown={e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); if (selectMode) onToggleSelect(place.id); else onOpenPlace(place.id) } }}
className={`col-lrow${active || selected ? ' sel' : ''}`}
>
{selectMode && (
<div className={`w-5 h-5 rounded-md flex items-center justify-center border shrink-0 ${selected ? 'bg-accent border-accent' : 'bg-surface-card border-edge'}`}>
{selected && <Check size={13} className="text-accent-text" strokeWidth={3} />}
</div>
{selectMode ? (
<span className={`col-lcheck${selected ? ' on' : ''}`}>{selected && <Check size={14} strokeWidth={3} />}</span>
) : (
<PlaceAvatar place={place} size={40} category={place.category ? { color: place.category.color ?? undefined, icon: place.category.icon ?? undefined } : null} />
)}
<PlaceAvatar place={place} size={36} category={place.category ? { color: place.category.color ?? undefined, icon: place.category.icon ?? undefined } : null} />
<div className="flex flex-col min-w-0 flex-1">
<span className="text-[13px] font-semibold text-content truncate">{place.name}</span>
<div className="li">
<div className="t">{place.name}</div>
{(place.category?.name || place.address) && (
<span className="text-[11px] text-content-faint truncate flex items-center gap-1">
{!place.category?.name && <MapPin size={10} />}
{place.category?.name || place.address}
</span>
<div className="s">
{!place.category?.name && <MapPin size={11} />}
<span>{place.category?.name || place.address}</span>
</div>
)}
</div>
<StatusBadge status={place.status} onChange={next => onStatusChange(place.id, next)} t={t} />
<StatusBadge status={place.status} onChange={selectMode ? undefined : next => onStatusChange(place.id, next)} t={t} />
</div>
)
})}
@@ -13,6 +13,8 @@ interface CollectionMapProps {
/**
* Map view — reuses the trip map stack (MapViewAuto → Leaflet / GL with marker
* clustering). One of the three list views; clicking a marker selects the place.
* 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 {
const pts = mappablePlaces(places)
@@ -24,7 +26,7 @@ export default function CollectionMap({ places, selectedPlaceId, onOpenPlace, da
: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png'
return (
<div className="rounded-xl overflow-hidden border border-edge" style={{ height: 'calc(100vh - var(--nav-h) - 180px)', minHeight: 360 }}>
<div style={{ width: '100%', height: '100%' }}>
<MapViewAuto
places={pts}
selectedPlaceId={selectedPlaceId}
+46 -59
View File
@@ -1,5 +1,5 @@
import React, { useEffect, useRef, useState } from 'react'
import { Plus, Bookmark, Layers, MoreHorizontal, Pencil, Trash2, Users, Check } from 'lucide-react'
import { Plus, Layers, MoreHorizontal, Pencil, Trash2, Users, Check, Palette } from 'lucide-react'
import type { Collection } from '@trek/shared'
import type { TranslationFn } from '../../types'
import { ALL_SAVED } from '../../store/collectionStore'
@@ -26,10 +26,6 @@ interface ListsRailProps {
t: TranslationFn
}
function ColorDot({ color }: { color?: string | null }): React.ReactElement {
return <span className="w-2.5 h-2.5 rounded-full shrink-0" style={{ background: color || '#6366f1' }} />
}
interface ListRowProps {
list: Collection
active: boolean
@@ -66,66 +62,62 @@ function ListRow({
if (editing) {
return (
<div className="px-2 py-1.5">
<div className="col-row">
<input
autoFocus
value={editingName}
onChange={e => setEditingName(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') onCommitRename(); if (e.key === 'Escape') onCommitRename() }}
onKeyDown={e => { if (e.key === 'Enter' || e.key === 'Escape') onCommitRename() }}
onBlur={onCommitRename}
className="w-full px-2 py-1.5 rounded-lg border border-accent bg-surface-input text-content text-[13px] outline-none"
className="col-row-edit"
/>
</div>
)
}
return (
<div ref={rowRef} className="relative group">
<button
type="button"
onClick={() => onSelect(list.id)}
className={`w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-left transition-colors ${active ? 'bg-surface-selected text-content' : 'text-content-secondary hover:bg-surface-hover'}`}
>
<ColorDot color={list.color} />
<span className="flex-1 text-[13px] font-medium truncate">{list.name}</span>
<span className="text-[11px] tabular-nums text-content-faint shrink-0">{list.place_count ?? 0}</span>
<div ref={rowRef} className="col-row">
<button type="button" onClick={() => onSelect(list.id)} className={`col-row-btn${active ? ' on' : ''}`}>
<span className="dot" style={{ background: list.color || '#6366f1' }} />
<span className="nm">{list.name}</span>
<span className="ct">{list.place_count ?? 0}</span>
</button>
<button
type="button"
onClick={e => { e.stopPropagation(); setMenuOpen(o => !o); setColorOpen(false) }}
className="absolute right-1.5 top-1/2 -translate-y-1/2 p-1 rounded-md text-content-faint opacity-0 group-hover:opacity-100 hover:bg-surface-hover transition-opacity"
className="col-row-menu"
aria-label={t('collections.listMenu')}
>
<MoreHorizontal size={15} />
</button>
{menuOpen && !colorOpen && (
<div className="absolute right-1 top-9 z-20 w-40 py-1 rounded-lg border border-edge bg-surface-card shadow-dropdown">
<button type="button" onClick={() => { setMenuOpen(false); onStartRename(list.id, list.name) }} className="w-full flex items-center gap-2 px-3 py-1.5 text-[12px] text-content-secondary hover:bg-surface-hover">
<Pencil size={13} /> {t('collections.editList')}
<div className="col-pop">
<button type="button" onClick={() => { setMenuOpen(false); onStartRename(list.id, list.name) }} className="col-pop-item">
<Pencil size={14} /> {t('collections.editList')}
</button>
<button type="button" onClick={() => setColorOpen(true)} className="w-full flex items-center gap-2 px-3 py-1.5 text-[12px] text-content-secondary hover:bg-surface-hover">
<ColorDot color={list.color} /> {t('collections.listColor')}
<button type="button" onClick={() => setColorOpen(true)} className="col-pop-item">
<Palette size={14} /> {t('collections.listColor')}
</button>
{canDelete && (
<button type="button" onClick={() => { setMenuOpen(false); onRequestDelete(list.id) }} className="w-full flex items-center gap-2 px-3 py-1.5 text-[12px] text-danger hover:bg-surface-hover">
<Trash2 size={13} /> {t('collections.deleteList')}
<button type="button" onClick={() => { setMenuOpen(false); onRequestDelete(list.id) }} className="col-pop-item danger">
<Trash2 size={14} /> {t('collections.deleteList')}
</button>
)}
</div>
)}
{colorOpen && (
<div className="absolute right-1 top-9 z-20 p-2 rounded-lg border border-edge bg-surface-card shadow-dropdown">
<div className="grid grid-cols-4 gap-1.5">
<div className="col-pop">
<div className="col-pop-swatches">
{SWATCHES.map(c => (
<button
key={c}
type="button"
onClick={() => { onSetColor(list.id, c); setColorOpen(false); setMenuOpen(false) }}
className="w-6 h-6 rounded-full flex items-center justify-center"
className="col-swatch"
style={{ background: c }}
aria-label={c}
>
{list.color === c && <Check size={13} className="text-white" strokeWidth={3} />}
{list.color === c && <Check size={13} strokeWidth={3} />}
</button>
))}
</div>
@@ -137,8 +129,10 @@ function ListRow({
/**
* Left rail of the user's lists: a "New list" action, the "All saved" union
* pseudo-list, owned lists (colour dot + count + rename/colour/delete menu),
* a shared section, and an incoming-invites block.
* pseudo-list, owned lists (colour dot + count + rename/colour/delete menu), a
* shared section, and an incoming-invites block. Styled with the collections
* glass tokens (`.col-*`); rendered both in the desktop rail and the mobile
* drawer.
*/
export default function ListsRail(props: ListsRailProps): React.ReactElement {
const {
@@ -149,25 +143,19 @@ export default function ListsRail(props: ListsRailProps): React.ReactElement {
} = props
return (
<div className="flex flex-col gap-1">
<button
type="button"
onClick={onNewList}
className="flex items-center gap-2 px-3 py-2 mb-1 rounded-lg border border-dashed border-edge text-content-secondary hover:bg-surface-hover hover:text-content transition-colors text-[13px] font-medium"
>
<Plus size={15} /> {t('collections.newList')}
<>
<button type="button" onClick={onNewList} className="col-rail-new">
<Plus size={16} /> {t('collections.newList')}
</button>
<button
type="button"
onClick={() => onSelect(ALL_SAVED)}
className={`w-full flex items-center gap-2.5 px-3 py-2 rounded-lg text-left transition-colors ${activeId === ALL_SAVED ? 'bg-surface-selected text-content' : 'text-content-secondary hover:bg-surface-hover'}`}
>
<Layers size={15} className="shrink-0 text-content-faint" />
<span className="flex-1 text-[13px] font-medium">{t('collections.allSaved')}</span>
</button>
<div className="col-row">
<button type="button" onClick={() => onSelect(ALL_SAVED)} className={`col-row-btn${activeId === ALL_SAVED ? ' on' : ''}`}>
<span className="ico"><Layers size={16} /></span>
<span className="nm">{t('collections.allSaved')}</span>
</button>
</div>
{ownedLists.length > 0 && <div className="h-px bg-edge-faint my-1.5" />}
{ownedLists.length > 0 && <div className="col-rail-sep" />}
{ownedLists.map(list => (
<ListRow
key={list.id}
@@ -187,9 +175,7 @@ export default function ListsRail(props: ListsRailProps): React.ReactElement {
{sharedLists.length > 0 && (
<>
<div className="flex items-center gap-1.5 px-3 mt-3 mb-1 text-[10px] font-semibold uppercase tracking-wider text-content-faint">
<Users size={11} /> {t('collections.shared')}
</div>
<div className="col-rail-label"><Users size={12} /> {t('collections.shared')}</div>
{sharedLists.map(list => (
<ListRow
key={list.id}
@@ -211,18 +197,19 @@ export default function ListsRail(props: ListsRailProps): React.ReactElement {
{incomingInvites.length > 0 && (
<>
<div className="flex items-center gap-1.5 px-3 mt-3 mb-1 text-[10px] font-semibold uppercase tracking-wider text-content-faint">
<Bookmark size={11} /> {t('collections.invites.title')} ({incomingInvites.length})
<div className="col-rail-label">
{t('collections.invites.title')}
<span className="badge">{incomingInvites.length}</span>
</div>
{incomingInvites.map(inv => (
<div key={inv.collection_id} className="px-3 py-2 rounded-lg bg-surface-secondary">
<p className="text-[12px] font-semibold text-content truncate">{inv.name}</p>
<p className="text-[11px] text-content-faint truncate">{t('collections.invites.from')} {inv.from.username}</p>
<div className="flex gap-1.5 mt-1.5">
<button type="button" onClick={() => onAcceptInvite(inv.collection_id)} className="flex-1 px-2 py-1 rounded-md bg-accent text-accent-text text-[11px] font-semibold hover:bg-accent-hover">
<div key={inv.collection_id} className="col-invite">
<div className="t">{inv.name}</div>
<div className="s">{t('collections.invites.from')} {inv.from.username}</div>
<div className="col-invite-actions">
<button type="button" onClick={() => onAcceptInvite(inv.collection_id)} className="col-invite-accept">
{t('collections.invites.accept')}
</button>
<button type="button" onClick={() => onDeclineInvite(inv.collection_id)} className="flex-1 px-2 py-1 rounded-md border border-edge text-content-secondary text-[11px] font-semibold hover:bg-surface-hover">
<button type="button" onClick={() => onDeclineInvite(inv.collection_id)} className="col-invite-decline">
{t('collections.invites.decline')}
</button>
</div>
@@ -230,6 +217,6 @@ export default function ListsRail(props: ListsRailProps): React.ReactElement {
))}
</>
)}
</div>
</>
)
}
@@ -9,22 +9,26 @@ interface StatusBadgeProps {
onChange?: (next: CollectionStatus) => void
showLabel?: boolean
size?: number
/** Dark-glass variant for a pill sitting over a photo cover / the hero. */
onCover?: boolean
t: TranslationFn
}
/**
* Coloured per-place status pill (idea / want-to-go / visited). When `onChange`
* is supplied a single tap cycles the status optimistically; otherwise it is a
* static badge. Looks intentional in both light and dark mode via the
* accent/success tokens in STATUS_META.
* static badge. Two skins: the default surface pill (list / inspector) and the
* `onCover` dark-glass pill that stays legible on top of a photo cover. Styled
* with utility classes only, so it works both inside and outside `.trek-dash`.
*/
export default function StatusBadge({ status, onChange, showLabel = true, size = 13, t }: StatusBadgeProps): React.ReactElement {
export default function StatusBadge({ status, onChange, showLabel = true, size = 13, onCover = false, t }: StatusBadgeProps): React.ReactElement {
const meta = STATUS_META[status]
const Icon = meta.icon
const label = t(meta.labelKey)
const color = onCover ? meta.coverColor : meta.color
const interactive = !!onChange
const handleClick = (e: React.MouseEvent) => {
const cycle = (e: React.SyntheticEvent) => {
if (!onChange) return
e.preventDefault()
e.stopPropagation()
@@ -33,26 +37,35 @@ export default function StatusBadge({ status, onChange, showLabel = true, size =
const content = (
<>
<Icon size={size} style={{ color: meta.color }} strokeWidth={2.2} />
{showLabel && <span className="font-semibold" style={{ color: meta.color }}>{label}</span>}
<Icon size={size} style={{ color }} strokeWidth={2.4} />
{showLabel && <span className="font-semibold" style={{ color }}>{label}</span>}
</>
)
const className = `inline-flex items-center gap-1.5 rounded-full text-[11px] leading-none ${showLabel ? 'px-2.5 py-1' : 'p-1.5'} border border-edge bg-surface-card/80 backdrop-blur-sm`
const skin = onCover
? 'bg-black/45 border-white/25 text-white'
: 'bg-surface-card/85 border-edge text-content'
const className = `inline-flex items-center gap-1.5 rounded-full text-[11px] leading-none border backdrop-blur-md ${showLabel ? 'px-2.5 py-1' : 'p-1.5'} ${skin}`
if (!interactive) {
return <span className={className} title={label}>{content}</span>
}
// Rendered as a role=button span (not a native <button>) on purpose: inside
// the .trek-dash scope the global `.trek-dash button` reset would strip the
// pill's background/border/padding, and the pill also has to sit inside the
// grid card's own clickable element without nesting one button in another.
return (
<button
type="button"
onClick={handleClick}
<span
role="button"
tabIndex={0}
onClick={cycle}
onKeyDown={e => { if (e.key === 'Enter' || e.key === ' ') cycle(e) }}
title={`${label} — ${t('collections.status.cycleHint')}`}
aria-label={label}
className={`${className} transition-transform hover:scale-105 active:scale-95 cursor-pointer`}
className={`${className} transition-transform hover:scale-110 active:scale-95 cursor-pointer select-none`}
>
{content}
</button>
</span>
)
}
@@ -0,0 +1,89 @@
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) }} />
})