feat: quality of life sweep from the feature discussions

Small requests from the discussions, each built end to end: planner and
map (cycling mode, date first headings, clear a day, stay times per day,
off-route stops, map lock, compact unplanned markers, pending stays,
cable car, transit quick picks), places (location filter, category from
OSM, open in maps, geo: link, image from an attachment, enrichment on
file import, places near a pin, place name language, Amap first in
China), lists and costs (packed counter, inherited sharing, Markdown
to-dos, payment notes, bookings CSV, my plan PDF), sharing (unplanned
places, travel only, without photos), journey (photo zoom, drafts,
photo order, trip suggestion, day jump), atlas (region counter, region
bucket list, places per country), vacay half company holidays, studio
copy and paste plus the book's own layouts, and RESTORE_FROM_BACKUP for
a first start restore.
This commit is contained in:
Maurice
2026-09-30 23:00:12 +02:00
parent 91dfab3f4b
commit 8fd46c4c18
691 changed files with 9491 additions and 927 deletions
@@ -1,4 +1,5 @@
import React, { useEffect, useMemo, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import tzlookup from 'tz-lookup'
import { ArrowLeftRight, ArrowRight, Bus, CableCar, ChevronDown, ChevronUp, Clock, Footprints, MapPin, Sailboat, Search, TramFront, TrainFront, TrainFrontTunnel } from 'lucide-react'
import CustomTimePicker from '../shared/CustomTimePicker'
@@ -8,7 +9,9 @@ import { useSettingsStore } from '../../store/settingsStore'
import { useToast } from '../shared/Toast'
import { useTranslation } from '../../i18n'
import { getDayBookendHotels } from '../../utils/dayOrder'
import type { Day, Place, Accommodation } from '../../types'
import type { Day, Place, Accommodation, Reservation } from '../../types'
import { useTripStore } from '../../store/tripStore'
import { isCarrierTransport } from '../../utils/dayMerge'
import type { TransitProvider } from '@trek/shared'
/**
@@ -110,13 +113,36 @@ function stayPick(a: Accommodation): PickedPlace | null {
return a.place_lat != null && a.place_lng != null && a.place_name ? { name: a.place_name, lat: a.place_lat, lng: a.place_lng } : null
}
/**
* The airports, stations and ports the day's flights, trains, buses and ferries leave
* from or arrive at (#1506): the way to the hotel after landing starts at one of them.
* An endpoint belongs to the day by its own local date, or, without one, by the leg's
* day: departures on the booking's first day, arrivals on its last.
*/
export function dayBookingStops(day: Pick<Day, 'id' | 'date'>, reservations: Reservation[]): PickedPlace[] {
const stops: PickedPlace[] = []
for (const r of reservations) {
if (!isCarrierTransport(r)) continue
const endDay = r.end_day_id ?? r.day_id
for (const ep of r.endpoints ?? []) {
if (ep.lat == null || ep.lng == null || !ep.name) continue
const onDay = ep.local_date
? !!day.date && ep.local_date.slice(0, 10) === day.date.slice(0, 10)
: (ep.role === 'from' && r.day_id === day.id) || (ep.role === 'to' && endDay === day.id)
if (onDay) stops.push({ name: ep.name, lat: ep.lat, lng: ep.lng })
}
}
return stops
}
/**
* What the from/to fields offer before anything is typed. The stay the day
* starts in and the one it ends in come first and are never cut, since most
* connections of a day begin or end there (#2538); then the day's own located
* connections of a day begin or end there (#2538); the day's airports and
* stations follow and are not cut either (#1506); then the day's own located
* places and the trip's other stays, up to MAX_QUICK_PICKS.
*/
function buildQuickPicks(day: Day, days: Day[], places: Place[], accommodations: Accommodation[]): PickedPlace[] {
export function buildQuickPicks(day: Day, days: Day[], places: Place[], accommodations: Accommodation[], bookingStops: PickedPlace[] = []): PickedPlace[] {
const { morning, evening } = getDayBookendHotels(day, days, accommodations)
const dayStays = [morning, evening].filter((a): a is Accommodation => a != null)
@@ -130,15 +156,55 @@ function buildQuickPicks(day: Day, days: Day[], places: Place[], accommodations:
}
const stays = dayStays.map(stayPick).filter(unique)
const stations = bookingStops.filter(unique)
const rest = [
...places.map(p => (p.lat != null && p.lng != null ? { name: p.name, lat: p.lat, lng: p.lng } : null)),
...accommodations.filter(a => !dayStays.includes(a)).map(stayPick),
].filter(unique)
return [...stays, ...rest.slice(0, MAX_QUICK_PICKS)]
return [...stays, ...stations, ...rest.slice(0, MAX_QUICK_PICKS)]
}
// ── from/to stop picker ──────────────────────────────────────────────────────
const LIST_GAP = 4
const LIST_MAX = 240
const VIEW_EDGE = 12
/**
* Where the suggestion list sits on screen: under the field, or above it when the
* window has no room below. Measured again on scroll and resize while it is open.
*/
function useFloatingList(anchorRef: React.RefObject<HTMLElement | null>, open: boolean) {
const [pos, setPos] = useState<{ left: number; width: number; top: number; bottom: number; above: boolean; maxHeight: number } | null>(null)
useEffect(() => {
if (!open) { setPos(null); return }
const place = () => {
const el = anchorRef.current
if (!el) return
const r = el.getBoundingClientRect()
const below = window.innerHeight - r.bottom - VIEW_EDGE
const aboveRoom = r.top - VIEW_EDGE
const above = below < 160 && aboveRoom > below
setPos({
left: r.left,
width: r.width,
top: r.bottom + LIST_GAP,
bottom: window.innerHeight - r.top + LIST_GAP,
above,
maxHeight: Math.max(120, Math.min(LIST_MAX, (above ? aboveRoom : below) - LIST_GAP)),
})
}
place()
window.addEventListener('resize', place)
window.addEventListener('scroll', place, true)
return () => {
window.removeEventListener('resize', place)
window.removeEventListener('scroll', place, true)
}
}, [open, anchorRef])
return pos
}
function StopPicker({ label, value, onPick, quickPicks, near, placeholder }: {
label: string
value: PickedPlace | null
@@ -153,9 +219,15 @@ function StopPicker({ label, value, onPick, quickPicks, near, placeholder }: {
const [open, setOpen] = useState(false)
const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const rootRef = useRef<HTMLDivElement>(null)
const fieldRef = useRef<HTMLDivElement>(null)
const listRef = useRef<HTMLDivElement>(null)
const listPos = useFloatingList(fieldRef, open)
useEffect(() => {
const close = (e: MouseEvent) => { if (!rootRef.current?.contains(e.target as Node)) setOpen(false) }
const close = (e: MouseEvent) => {
const target = e.target as Node
if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) setOpen(false)
}
document.addEventListener('mousedown', close)
return () => document.removeEventListener('mousedown', close)
}, [])
@@ -179,7 +251,7 @@ function StopPicker({ label, value, onPick, quickPicks, near, placeholder }: {
return (
<div ref={rootRef} style={{ position: 'relative', flex: 1, minWidth: 0 }}>
<label className="block text-[11px] font-semibold text-content-faint mb-[5px] uppercase tracking-[0.03em]">{label}</label>
<div className="bg-surface-input border border-edge" style={{ display: 'flex', alignItems: 'center', gap: 7, borderRadius: 10, padding: '0 10px', height: 38 }}>
<div ref={fieldRef} className="bg-surface-input border border-edge" style={{ display: 'flex', alignItems: 'center', gap: 7, borderRadius: 10, padding: '0 10px', height: 38 }}>
<MapPin size={14} className="text-content-faint" style={{ flexShrink: 0 }} />
<input
value={display}
@@ -190,8 +262,10 @@ function StopPicker({ label, value, onPick, quickPicks, near, placeholder }: {
style={{ border: 0, background: 'none', outline: 'none', fontSize: 'calc(13px * var(--fs-scale-body, 1))', width: '100%', fontFamily: 'inherit' }}
/>
</div>
{open && (results.length > 0 || (!value && text.trim().length < 2 && quickPicks.length > 0)) && (
<div className="bg-surface-card border border-edge" style={{ position: 'absolute', top: '100%', left: 0, right: 0, marginTop: 4, borderRadius: 10, boxShadow: '0 8px 32px rgba(0,0,0,0.14)', zIndex: 30, overflow: 'hidden', maxHeight: 240, overflowY: 'auto' }}>
{open && listPos && (results.length > 0 || (!value && text.trim().length < 2 && quickPicks.length > 0)) && createPortal(
// On the page rather than inside the dialog, so a dialog that scrolls or clips
// its content cannot cut the list off before anything is typed.
<div ref={listRef} className="bg-surface-card border border-edge z-[var(--z-toast)]" style={{ position: 'fixed', left: listPos.left, width: listPos.width, ...(listPos.above ? { bottom: listPos.bottom } : { top: listPos.top }), borderRadius: 10, boxShadow: 'var(--shadow-dropdown)', overflow: 'hidden', maxHeight: listPos.maxHeight, overflowY: 'auto' }}>
{results.length > 0
? results.map((r, i) => (
<button type="button" key={i} onClick={() => { onPick({ name: r.name, lat: r.lat, lng: r.lng }); setText(''); setResults([]); setOpen(false) }}
@@ -202,7 +276,7 @@ function StopPicker({ label, value, onPick, quickPicks, near, placeholder }: {
<MapPin size={13} className="text-content-faint" style={{ flexShrink: 0 }} />
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{r.name}
{r.area && <span className="text-content-faint"> · {r.area}</span>}
{r.area && <span className="ml-1.5 text-content-faint">{r.area}</span>}
</span>
</button>
))
@@ -216,7 +290,8 @@ function StopPicker({ label, value, onPick, quickPicks, near, placeholder }: {
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{p.name}</span>
</button>
))}
</div>
</div>,
document.body,
)}
</div>
)
@@ -402,7 +477,11 @@ export default function TransitSearchPanel({ day, days, places, accommodations =
const [addingIdx, setAddingIdx] = useState<number | null>(null)
const [provider, setProvider] = useState<TransitProvider | null>(null)
const quickPicks = useMemo(() => buildQuickPicks(day, days, places, accommodations), [day, days, places, accommodations])
const reservations = useTripStore(s => s.reservations)
const quickPicks = useMemo(
() => buildQuickPicks(day, days, places, accommodations, dayBookingStops(day, reservations)),
[day, days, places, accommodations, reservations],
)
const near = quickPicks.length > 0 ? `${quickPicks[0].lat},${quickPicks[0].lng}` : null