mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
01d327b502
- Collections is Places now: /places opens "All places", every place of the trips and lists with where it comes from, the same filter row (where from, status, category, order), map bar (search, lock, list toggle) and place sheet as a list; /places/saved and /places/:id are the lists, and the old /collections links still land there. On the phone the same, with its own sheet. A place sheet shows each trip (planned day or trip dates, stay, booking, notes) and each list (status, labels, rating, notes) as one row that opens it. - The rail: a calm "New list" with its plus tile, All places and All saved as views, a "My lists" heading, every name on one edge. Lists can carry one of 24 symbols, shown in their colour in the rail and the editor. - A saved place's row keeps to two lines: its category as an icon before the name, its average vote as a star on the picture. Map pins wear the same star. - The place forms put the category in front of the name as a tile that opens the category list, instead of a row of chips. - All saved gets a subtitle; the import dialog opens centred. - Fixes: a pasted coordinate pair splits from either field of the place form; "more" in All places frees itself when a filter changes mid-load; place names on the trip map and the rating badge follow the reading direction.
121 lines
5.8 KiB
TypeScript
121 lines
5.8 KiB
TypeScript
import React, { useEffect, useMemo, useRef } from 'react'
|
|
import { Check, GripVertical, Info, MapPin, Star } from 'lucide-react'
|
|
import type { CollectionPlace, CollectionStatus, CollectionLabel } from '@trek/shared'
|
|
import type { TranslationFn } from '../../types'
|
|
import PlaceAvatar from '../shared/PlaceAvatar'
|
|
import StatusBadge from './StatusBadge'
|
|
import CollectionPlaceTags from './CollectionPlaceTags'
|
|
import { usePlaceReorder } from './usePlaceReorder'
|
|
import CategoryBadge from './CategoryBadge'
|
|
|
|
/** A vote average as the map's pins write it: a whole number bare, else one decimal. */
|
|
const ratingLabel = (rating: number): string => (Number.isInteger(rating) ? String(rating) : rating.toFixed(1))
|
|
|
|
|
|
interface CollectionListProps {
|
|
places: CollectionPlace[]
|
|
labels: CollectionLabel[]
|
|
selectedPlaceId: number | null
|
|
selectMode: boolean
|
|
selectedIds: number[]
|
|
onOpenPlace: (id: number) => void
|
|
onStatusChange?: (placeId: number, status: CollectionStatus) => void
|
|
onToggleSelect: (id: number) => void
|
|
/** The list's own order may be dragged right now (#1457). */
|
|
reorderEnabled?: boolean
|
|
/** It could be, but a search or filter hides places, so the list says why not. */
|
|
reorderBlocked?: boolean
|
|
onReorder?: (orderedIds: number[]) => void
|
|
t: TranslationFn
|
|
}
|
|
|
|
/**
|
|
* 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, labels, selectedPlaceId, selectMode, selectedIds, onOpenPlace, onStatusChange, onToggleSelect,
|
|
reorderEnabled = false, reorderBlocked = false, onReorder, t,
|
|
}: CollectionListProps): React.ReactElement {
|
|
const labelsById = useMemo(() => new Map(labels.map(l => [l.id, l])), [labels])
|
|
// Bring the selected row into view — e.g. when it was picked from the map.
|
|
const selectedRef = useRef<HTMLDivElement>(null)
|
|
useEffect(() => {
|
|
selectedRef.current?.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
|
|
}, [selectedPlaceId])
|
|
|
|
const order = useMemo(() => places.map(p => p.id), [places])
|
|
const reorder = usePlaceReorder(order, reorderEnabled && !!onReorder, ids => onReorder?.(ids))
|
|
|
|
return (
|
|
<div className="col-listview">
|
|
{reorderBlocked && (
|
|
<p className="col-reorder-note"><Info size={13} /> {t('collections.reorderBlocked')}</p>
|
|
)}
|
|
{places.map(place => {
|
|
const selected = selectedIds.includes(place.id)
|
|
const active = selectedPlaceId === place.id
|
|
const placeLabels = (place.label_ids ?? []).map(id => labelsById.get(id)).filter(Boolean) as CollectionLabel[]
|
|
return (
|
|
<div
|
|
key={place.id}
|
|
ref={active ? selectedRef : undefined}
|
|
role="button"
|
|
// Opt out of the global :active press-scale: shrinking the row-wide button
|
|
// slides the status badge out from under the pointer mid-click, so the click
|
|
// retargets onto the row and opens the place instead of cycling (#2158).
|
|
data-no-press
|
|
tabIndex={0}
|
|
onClick={() => (selectMode ? onToggleSelect(place.id) : onOpenPlace(place.id))}
|
|
onKeyDown={e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); if (selectMode) onToggleSelect(place.id); else onOpenPlace(place.id) } }}
|
|
className={`col-lrow col-lrow-place${active || selected ? ' sel' : ''}${reorder.enabled ? ' can-reorder' : ''}${reorder.dragId === place.id ? ' dragging' : ''}${reorder.dropSide(place.id) ? ` drop-${reorder.dropSide(place.id)}` : ''}`}
|
|
{...reorder.rowProps(place.id)}
|
|
>
|
|
{reorder.enabled && (
|
|
<span
|
|
className="col-lgrip"
|
|
role="button"
|
|
tabIndex={0}
|
|
aria-label={t('collections.reorderHandle', { name: place.name })}
|
|
onClick={e => e.stopPropagation()}
|
|
{...reorder.handleProps(place.id)}
|
|
>
|
|
<GripVertical size={14} />
|
|
</span>
|
|
)}
|
|
{selectMode ? (
|
|
<span className={`col-lcheck${selected ? ' on' : ''}`}>{selected && <Check size={14} strokeWidth={3} />}</span>
|
|
) : (
|
|
<span className="col-lrow-avatar">
|
|
<PlaceAvatar place={place} size={40} category={place.category ? { color: place.category.color ?? undefined, icon: place.category.icon ?? undefined } : null} />
|
|
{/* The category rides on the tile's corner, so the row keeps to two lines. */}
|
|
{/* The list's average vote on the other corner, so the row needs no line for it. */}
|
|
{typeof place.rating_avg === 'number' && place.rating_avg > 0 && (
|
|
<span className="col-lrow-ratebadge" role="img" aria-label={t('collections.ratingBadge', { rating: ratingLabel(place.rating_avg) })}>
|
|
<Star aria-hidden="true" />
|
|
<span className={Number.isInteger(place.rating_avg) ? 'n' : 'n frac'}>{ratingLabel(place.rating_avg)}</span>
|
|
</span>
|
|
)}
|
|
</span>
|
|
)}
|
|
<div className="li">
|
|
<div className="t">{place.category?.name && <CategoryBadge category={place.category} />}<span className="nm">{place.name}</span></div>
|
|
{place.address && (
|
|
<div className="s">
|
|
<MapPin size={11} />
|
|
<span>{place.address}</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
<CollectionPlaceTags place={place} labels={placeLabels} showCategory={false} />
|
|
<div className="col-lrow-status">
|
|
<StatusBadge status={place.status} onChange={selectMode || !onStatusChange ? undefined : next => onStatusChange(place.id, next)} t={t} />
|
|
</div>
|
|
</div>
|
|
)
|
|
})}
|
|
</div>
|
|
)
|
|
}
|