feat(places): one place view for All places and the lists

The desktop dialog and the phone sheet of a place show its overview, notes,
tours and bookings, photos and files and its history in tabs, with the tags
of each list and trip, a markdown notes editor, uploads and the place
picture. The rating bar of All places is the rating row the lists show,
with its voters, and votes once for every copy. All places filters by a
lowest rating and sorts by it, and the edit form changes the first copy the
reader may edit, which the server carries to the others.
This commit is contained in:
Maurice
2026-11-29 23:36:43 +00:00
parent 783c98f41e
commit d758f4c592
78 changed files with 5604 additions and 2797 deletions
@@ -6,9 +6,8 @@ import Markdown from 'react-markdown'
import remarkGfm from 'remark-gfm'
import remarkBreaks from 'remark-breaks'
import { markdownLinkComponents } from '../shared/markdownLink'
import { Clock, MapPin, ExternalLink, Pencil, Plus, Minus, ChevronDown, ChevronUp, ChevronRight, FileText, Upload, File, FileImage, Navigation, Mountain, Bookmark, BookmarkCheck, Copy, Trash2 } from 'lucide-react'
import { Clock, MapPin, ExternalLink, Pencil, Plus, Minus, ChevronDown, ChevronUp, FileText, Upload, File, FileImage, Navigation, Mountain, Bookmark, BookmarkCheck, Copy, Trash2 } from 'lucide-react'
import { hoursLines, periodsFromWeek } from './placeHours'
import { BlurredCode } from '../shared/BookingCode'
import PlaceRating from '../shared/StarRating'
import TrackColorPicker from '../shared/TrackColorPicker'
import { resolveTrackColor, inheritedTrackColor } from '../Map/trackColors'
@@ -28,7 +27,7 @@ import { usePluginStore } from '../../store/pluginStore'
import PluginFrame from '../Plugins/PluginFrame'
import type { Place, Category, Day, Reservation, TripFile, AssignmentsMap, DistanceUnit } from '../../types'
import type { CollectionStatus } from '@trek/shared'
import { splitReservationDateTime, formatTime, formatMoney } from '../../utils/formatters'
import { formatTime, formatMoney } from '../../utils/formatters'
import { useTripStore } from '../../store/tripStore'
import { useCanDo } from '../../store/permissionsStore'
import { formatDistance, formatElevation } from '../../utils/units'
@@ -41,11 +40,11 @@ import { convertHoursLine } from './placeHoursFormat'
import type { EndDayControlProps } from '../Roadtrip/EndDayControl'
import VisitControls, { type RoadtripStayControl } from '../Roadtrip/VisitControls'
import { DialogButton, DialogIconButton, DialogSection, DeleteButton, FooterSpacer, fs } from '../shared/DialogShell'
import { BOX, Field, TypeTile, toneOf, toneTint, useOpenFile } from './bookings/bookingParts'
import { BOX, useOpenFile } from './bookings/bookingParts'
import TripPlaceVisits from '../Collections/TripPlaceVisits'
import { parseMeta } from './bookings/bookingsModel'
import { MoreButton, SoftPill } from './planParts'
import { InspectorHead } from './PlaceInspectorHead'
import LinkedBookingCard from './PlaceLinkedBookingCard'
import { usePlaceLanguage } from '../../hooks/usePlaceLanguage'
import { participantsWith, participantsWithout, splitParticipants, usePlaceFileUpload } from './usePlaceActions'
@@ -632,97 +631,6 @@ function PlaceBookingsAndPeople({ selectedAssignmentId, placeId, reservations, a
)
}
/** The facts of a booking's metadata that the card has no field for, one pill each. */
function bookingMetaParts(res: Reservation, t: (key: string) => string): string[] {
const meta = parseMeta(res)
const parts: string[] = []
if (meta.airline && meta.flight_number) parts.push(`${meta.airline} ${meta.flight_number}`)
else if (meta.flight_number) parts.push(meta.flight_number)
if (meta.departure_airport && meta.arrival_airport) parts.push(`${meta.departure_airport} → ${meta.arrival_airport}`)
if (meta.train_number) parts.push(meta.train_number)
if (meta.platform) parts.push(`${t('reservations.meta.platform')} ${meta.platform}`)
if (meta.check_in_time) parts.push(`${t('reservations.meta.checkIn')} ${meta.check_in_time}`)
if (meta.check_out_time) parts.push(`${t('reservations.meta.checkOut')} ${meta.check_out_time}`)
return parts
}
/**
* A booking on this stop as a small booking card: the head band tinted by its
* status, then its date, time and code as fields. With `open` it opens the
* booking's detail or its editor (`opens`) on a click, Enter or Space; without
* it the card is a read-only summary.
*/
function LinkedBookingCard({ res, timeFormat, open, opens = 'editor' }: { res: Reservation; timeFormat: string; open?: () => void; opens?: 'detail' | 'editor' }) {
const { t, locale } = useTranslation()
const openLabel = t(opens === 'detail' ? 'roadtrip.ride.open' : 'inspector.editRes')
// A stop can carry several bookings (#2201), so a card that opens its booking is
// named by it; the editor's card keeps its old name.
const cardName = opens === 'detail' ? `${openLabel}: ${res.title}` : openLabel
const OpenGlyph = opens === 'detail' ? ChevronRight : Pencil
const confirmed = res.status === 'confirmed'
const { date, time: startTime } = splitReservationDateTime(res.reservation_time)
const { time: endTime } = splitReservationDateTime(res.reservation_end_time)
const metaParts = bookingMetaParts(res, t)
const hasFields = !!(date || startTime || endTime || res.confirmation_number)
const card = (
<div
role={open ? 'button' : undefined}
// No press-scale on the composite card: shrinking it mid-click slides the
// links inside out from under the pointer (#2158).
data-no-press
aria-label={open ? cardName : undefined}
tabIndex={open ? 0 : undefined}
onClick={open}
onKeyDown={open ? (e: React.KeyboardEvent) => {
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); open() }
} : undefined}
className={`group flex flex-col overflow-hidden rounded-xl border border-edge-faint bg-surface-secondary text-start ${open ? 'cursor-pointer transition-shadow hover:shadow-md focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-[color:var(--text-primary)]' : ''}`}
>
<div className="flex items-center gap-2 px-2.5 py-1.5" style={{ background: toneTint(toneOf(res)) }}>
<TypeTile type={res.type} size={24} />
<span className="min-w-0 flex-1 truncate font-bold text-content" style={fs(12.5, 'body')}>{res.title}</span>
<SoftPill tone={confirmed ? 'success' : 'warning'} caps>{confirmed ? t('reservations.confirmed') : t('reservations.pending')}</SoftPill>
{open && <OpenGlyph size={12} strokeWidth={2} aria-hidden className="flex-none text-content-faint opacity-60 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100" />}
</div>
{(hasFields || metaParts.length > 0 || res.notes) && (
<div className="flex flex-col gap-2 border-t border-edge-faint px-2.5 pb-2.5 pt-2">
{hasFields && (
<div className="flex gap-2">
{date && (
<Field label={t('reservations.date')} className="flex-1">
{new Date(date + 'T00:00:00Z').toLocaleDateString(locale, { weekday: 'short', day: 'numeric', month: 'short', timeZone: 'UTC' })}
</Field>
)}
{(startTime || endTime) && (
<Field label={t('reservations.time')} className="flex-1" tabular>
{startTime ? formatTime(startTime, locale, timeFormat) : ''}
{endTime ? ` – ${formatTime(endTime, locale, timeFormat)}` : ''}
</Field>
)}
{res.confirmation_number && (
<Field label={t('reservations.confirmationCode')} className="flex-1" tabular>
<BlurredCode className="font-geist">{res.confirmation_number}</BlurredCode>
</Field>
)}
</div>
)}
{metaParts.length > 0 && (
<div className="flex flex-wrap gap-1">
{metaParts.map((part, i) => <SoftPill key={i}>{part}</SoftPill>)}
</div>
)}
{res.notes && (
<div className="collab-note-md text-content-muted" style={{ ...fs(11.5, 'body'), lineHeight: 1.45, wordBreak: 'break-word', overflowWrap: 'anywhere' }}>
<Markdown remarkPlugins={[remarkGfm, remarkBreaks]} components={markdownLinkComponents}>{res.notes}</Markdown>
</div>
)}
</div>
)}
</div>
)
return open ? <Tooltip label={openLabel} placement="top">{card}</Tooltip> : card
}
function MemberAvatar({ member, size }: { member: TripMember; size: number }) {
const src = member.avatar_url || avatarSrc(member.avatar)
return (
@@ -0,0 +1,152 @@
import { ChevronRight, Pencil } from 'lucide-react';
import React from 'react';
import Markdown from 'react-markdown';
import remarkBreaks from 'remark-breaks';
import remarkGfm from 'remark-gfm';
import { useTranslation } from '../../i18n';
import type { Reservation } from '../../types';
import { formatTime, splitReservationDateTime } from '../../utils/formatters';
import { BlurredCode } from '../shared/BookingCode';
import { fs } from '../shared/DialogShell';
import { markdownLinkComponents } from '../shared/markdownLink';
import { Tooltip } from '../shared/Tooltip';
import { Field, TypeTile, toneOf, toneTint } from './bookings/bookingParts';
import { parseMeta } from './bookings/bookingsModel';
import { SoftPill } from './planParts';
/** The facts of a booking's metadata that the card has no field for, one pill each. */
function bookingMetaParts(res: Reservation, t: (key: string) => string): string[] {
const meta = parseMeta(res);
const parts: string[] = [];
if (meta.airline && meta.flight_number) parts.push(`${meta.airline} ${meta.flight_number}`);
else if (meta.flight_number) parts.push(meta.flight_number);
if (meta.departure_airport && meta.arrival_airport) parts.push(`${meta.departure_airport} → ${meta.arrival_airport}`);
if (meta.train_number) parts.push(meta.train_number);
if (meta.platform) parts.push(`${t('reservations.meta.platform')} ${meta.platform}`);
if (meta.check_in_time) parts.push(`${t('reservations.meta.checkIn')} ${meta.check_in_time}`);
if (meta.check_out_time) parts.push(`${t('reservations.meta.checkOut')} ${meta.check_out_time}`);
return parts;
}
/**
* A booking on a stop of the place inspector as a small booking card: the head
* band tinted by its status, then its date, time and code as fields. With
* `open` it opens the booking's detail or its editor (`opens`) on a click,
* Enter or Space; without it the card is a read-only summary.
*/
export default function LinkedBookingCard({
res,
timeFormat,
open,
opens = 'editor',
}: {
res: Reservation;
timeFormat: string;
open?: () => void;
opens?: 'detail' | 'editor';
}) {
const { t, locale } = useTranslation();
const openLabel = t(opens === 'detail' ? 'roadtrip.ride.open' : 'inspector.editRes');
// A stop can carry several bookings (#2201), so a card that opens its booking is
// named by it; the editor's card keeps its old name.
const cardName = opens === 'detail' ? `${openLabel}: ${res.title}` : openLabel;
const OpenGlyph = opens === 'detail' ? ChevronRight : Pencil;
const confirmed = res.status === 'confirmed';
const { date, time: startTime } = splitReservationDateTime(res.reservation_time);
const { time: endTime } = splitReservationDateTime(res.reservation_end_time);
const metaParts = bookingMetaParts(res, t);
const hasFields = !!(date || startTime || endTime || res.confirmation_number);
const card = (
<div
role={open ? 'button' : undefined}
// No press-scale on the composite card: shrinking it mid-click slides the
// links inside out from under the pointer (#2158).
data-no-press
aria-label={open ? cardName : undefined}
tabIndex={open ? 0 : undefined}
onClick={open}
onKeyDown={
open
? (e: React.KeyboardEvent) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
open();
}
}
: undefined
}
className={`group flex flex-col overflow-hidden rounded-xl border border-edge-faint bg-surface-secondary text-start ${open ? 'cursor-pointer transition-shadow hover:shadow-md focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-[color:var(--text-primary)]' : ''}`}
>
<div className="flex items-center gap-2 px-2.5 py-1.5" style={{ background: toneTint(toneOf(res)) }}>
<TypeTile type={res.type} size={24} />
<span className="min-w-0 flex-1 truncate font-bold text-content" style={fs(12.5, 'body')}>
{res.title}
</span>
<SoftPill tone={confirmed ? 'success' : 'warning'} caps>
{confirmed ? t('reservations.confirmed') : t('reservations.pending')}
</SoftPill>
{open && (
<OpenGlyph
size={12}
strokeWidth={2}
aria-hidden
className="flex-none text-content-faint opacity-60 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"
/>
)}
</div>
{(hasFields || metaParts.length > 0 || res.notes) && (
<div className="flex flex-col gap-2 border-t border-edge-faint px-2.5 pb-2.5 pt-2">
{hasFields && (
<div className="flex gap-2">
{date && (
<Field label={t('reservations.date')} className="flex-1">
{new Date(date + 'T00:00:00Z').toLocaleDateString(locale, {
weekday: 'short',
day: 'numeric',
month: 'short',
timeZone: 'UTC',
})}
</Field>
)}
{(startTime || endTime) && (
<Field label={t('reservations.time')} className="flex-1" tabular>
{startTime ? formatTime(startTime, locale, timeFormat) : ''}
{endTime ? ` – ${formatTime(endTime, locale, timeFormat)}` : ''}
</Field>
)}
{res.confirmation_number && (
<Field label={t('reservations.confirmationCode')} className="flex-1" tabular>
<BlurredCode className="font-geist">{res.confirmation_number}</BlurredCode>
</Field>
)}
</div>
)}
{metaParts.length > 0 && (
<div className="flex flex-wrap gap-1">
{metaParts.map((part, i) => (
<SoftPill key={i}>{part}</SoftPill>
))}
</div>
)}
{res.notes && (
<div
className="collab-note-md text-content-muted"
style={{ ...fs(11.5, 'body'), lineHeight: 1.45, wordBreak: 'break-word', overflowWrap: 'anywhere' }}
>
<Markdown remarkPlugins={[remarkGfm, remarkBreaks]} components={markdownLinkComponents}>
{res.notes}
</Markdown>
</div>
)}
</div>
)}
</div>
);
return open ? (
<Tooltip label={openLabel} placement="top">
{card}
</Tooltip>
) : (
card
);
}