Jump to today, map-app links, drag to day, PDF landing time (#1891)

* Open a running trip on today

Asked for in discussion #1567: during a trip, opening the planner starts
at day 1 and you scroll to find out what is planned for today.

The mobile shell has done this since the plan tab was built - it seeds
the active day with today when the trip is running. The desktop day plan
never did, so the same trip behaved differently depending on the screen
you opened it on. It now selects today's day, expands it and scrolls it
into view, once per mount and only while nothing is selected yet, so a
deep link or a day picked before switching tabs still wins.

The date comparison moved into one helper both sides use. It is
deliberately local rather than toISOString(): 08:00 in Tokyo is still
yesterday in UTC, and a trip day is a calendar day where the traveller
is standing.

Also fixes a note losing its colour when dragged to another day. A move
is a delete plus a create, and the create was still sending the three
fields notes had before colours existed.

* Open a collection place in a map app

Asked for in discussion #1455: a saved place is somewhere you intend to
go, but the only way to get directions to one was to add it to a trip
first, where the button has been for a while.

The collection detail gets the same picker off the same helper: Google
Maps, Waze, Apple Maps and OpenStreetMap, filtered by what the place can
actually be located with. A place with coordinates offers all of them; a
place typed in by hand with just a name and an address still offers the
two that take a search string, and a place with neither shows no button
at all.

It sits on the meta line beside the address, quieter than the link chips
below it, because it is an action on the place rather than a piece of it.

* Drag a place off the map onto a day

Asked for in discussion #891: assigning a place means finding it again in
the sidebar, even though it is right there under the cursor on the map.

The drop half already existed and did not need touching. Every day, every
row and every gap between rows in the day plan reads a placeId and calls
onAssignToDay with the position it was dropped at, complete with the
toast and the undo entry. What was missing was a second place to pick a
place UP from - the only one was the row in the places sidebar.

Markers become that second source. Both renderers build their markers as
real DOM nodes, so one helper covers Leaflet and the GL variants alike,
and it sets the same two channels the sidebar row does: dataTransfer for
the drop, and window.__dragData because browsers hide dataTransfer while
the pointer is merely hovering. The day plan cannot tell the two apart.

Not offered on touch: HTML5 drag is a pointer feature, and on a phone
the day plan is not on screen next to the map anyway.

* Show the landing time in the PDF

Asked for in discussion #1310: the export prints a flight's departure and
nothing else, so a reader cannot tell how much of the day is left for
anything after it.

The day plan has drawn both times as "14:30 - 16:45" for a while; the
export never got the rule. Now it does, for any transport that begins and
ends on the same day - a train and a ferry read the same way a flight
does.

Across a span it stays as it was: the arrival belongs to the arrival day,
which already prints it as its own time, and repeating it on the
departure day would put tomorrow's clock next to today's departure.
This commit is contained in:
Maurice
2026-08-11 23:26:58 +02:00
committed by GitHub
parent 92b9e7548e
commit 62bc7ff8fd
17 changed files with 551 additions and 13 deletions
@@ -16,6 +16,7 @@ import {
import type { Accommodation, Reservation } from '../../types'
import { calculateRouteWithLegs, generateGoogleMapsUrl } from '../Map/RouteCalculator'
import DayPlanSidebar from './DayPlanSidebar'
import { makeMarkerDraggable } from '../Map/markerDrag'
// ── Hoisted mock state (accessible in vi.mock factories) ────────────────────
const mockDayNotesState = vi.hoisted(() => ({
@@ -1022,6 +1023,31 @@ describe('DayPlanSidebar', () => {
// ── Drop on day header (placeId) ───────────────────────────────────────
it('FE-PLANNER-DAYPLAN-199: a drag started on a map marker lands on the day (#891)', () => {
const day = buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' })
const onAssignToDay = vi.fn()
render(<DayPlanSidebar {...makeDefaultProps({ days: [day], onAssignToDay })} />)
// Exactly what makeMarkerDraggable leaves behind on dragstart — the point of
// this test is that the day plan cannot tell a marker from a sidebar row.
const marker = document.createElement('div')
document.body.appendChild(marker)
makeMarkerDraggable(marker, 42)
const dragstart = new Event('dragstart', { bubbles: true })
const store = new Map<string, string>()
Object.defineProperty(dragstart, 'dataTransfer', {
value: { setData: (k: string, v: string) => store.set(k, v), getData: (k: string) => store.get(k) ?? '', effectAllowed: 'none' },
})
marker.dispatchEvent(dragstart)
const dayHeader = screen.getByText('Day 1').closest('[style*="cursor: pointer"]')
fireEvent.drop(dayHeader as Element, { dataTransfer: { getData: (k: string) => store.get(k) ?? '' } })
expect(onAssignToDay).toHaveBeenCalledWith(42, 10)
marker.remove()
window.__dragData = null
})
it('FE-PLANNER-DAYPLAN-050: dropping place from sidebar onto day header calls onAssignToDay', () => {
const day = buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' })
const onAssignToDay = vi.fn()
@@ -1198,6 +1224,54 @@ describe('DayPlanSidebar', () => {
expect(mockDayNotesState.saveNote).toHaveBeenCalledWith(10)
})
// ── Jump to today (#1567) ─────────────────────────────────────────────
describe('jump to today', () => {
const isoDaysAround = (offsets: number[]) => offsets.map((o, i) => {
const d = new Date()
d.setDate(d.getDate() + o)
const iso = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
return buildDay({ id: 10 + i, date: iso, title: `Day ${i + 1}` })
})
it('FE-PLANNER-DAYPLAN-195: opening a running trip selects today rather than day one', async () => {
const onSelectDay = vi.fn()
const days = isoDaysAround([-1, 0, 1])
render(<DayPlanSidebar {...makeDefaultProps({ days, onSelectDay })} />)
await waitFor(() => expect(onSelectDay).toHaveBeenCalledWith(days[1].id, true))
})
it('FE-PLANNER-DAYPLAN-196: a trip that is not running is left alone', async () => {
const onSelectDay = vi.fn()
const days = isoDaysAround([5, 6, 7])
render(<DayPlanSidebar {...makeDefaultProps({ days, onSelectDay })} />)
await new Promise(r => setTimeout(r, 30))
expect(onSelectDay).not.toHaveBeenCalled()
})
it('FE-PLANNER-DAYPLAN-197: a day the user already picked wins over the jump', async () => {
const onSelectDay = vi.fn()
const days = isoDaysAround([-1, 0, 1])
// Coming back from another tab, or in via a deep link: the selection is
// already made and must not be overruled.
render(<DayPlanSidebar {...makeDefaultProps({ days, onSelectDay, selectedDayId: days[0].id })} />)
await new Promise(r => setTimeout(r, 30))
expect(onSelectDay).not.toHaveBeenCalled()
})
it('FE-PLANNER-DAYPLAN-198: a trip planned without dates has nothing to jump to', async () => {
const onSelectDay = vi.fn()
const days = [buildDay({ id: 1, date: null, title: 'Day 1' }), buildDay({ id: 2, date: null, title: 'Day 2' })]
render(<DayPlanSidebar {...makeDefaultProps({ days, onSelectDay })} />)
await new Promise(r => setTimeout(r, 30))
expect(onSelectDay).not.toHaveBeenCalled()
})
})
// ── Note colours and formatting (#1629) ───────────────────────────────
it('FE-PLANNER-DAYPLAN-192: the note dialog offers the palette and reports the pick', async () => {
@@ -2,7 +2,7 @@
interface DragDataPayload { placeId?: string; assignmentId?: string; noteId?: string; reservationId?: string; fromDayId?: string; phase?: 'single' | 'start' | 'middle' | 'end' }
declare global { interface Window { __dragData: DragDataPayload | null } }
import React, { useState, useEffect, useLayoutEffect, useRef, useMemo } from 'react'
import React, { useState, useEffect, useLayoutEffect, useRef, useMemo, useCallback } from 'react'
import { avatarSrc } from '../../utils/avatarSrc'
import { ChevronDown, ChevronRight, ChevronUp, Navigation, RotateCcw, ExternalLink, Clock, Pencil, GripVertical, Ticket, Plus, FileText, Trash2, Car, Lock, Hotel, Footprints, Route as RouteIcon, Bookmark, TramFront, Zap } from 'lucide-react'
import { assignmentsApi, reservationsApi, daysApi } from '../../api/client'
@@ -35,6 +35,7 @@ import { useDayNotes } from '../../hooks/useDayNotes'
import { useExchangeRates } from '../../hooks/useExchangeRates'
import { RES_ICONS, getNoteIcon } from './DayPlanSidebar.constants'
import { noteSurface } from './noteSurface'
import { findTodayDayId } from './today'
import { markdownLinkComponents } from '../shared/markdownLink'
import { RouteConnector, HotelRouteConnector } from './DayPlanSidebarRouteConnector'
import { usePluginDaySchedule, usePluginDayTints, dayTintBackground, dayTinted, PluginDayScheduleRow, formatScheduleMinutes } from '../Plugins/PluginDaySchedule'
@@ -226,6 +227,39 @@ function useDayPlanSidebar(props: DayPlanSidebarProps) {
} | null>(null)
const dragDataRef = useRef(null)
const scrollContainerRef = useRef<HTMLDivElement | null>(null)
const dayRefs = useRef<Map<number, HTMLElement>>(new Map())
/** The day that is today, or null when the trip is not running right now. */
const todayDayId = useMemo(() => findTodayDayId(days), [days])
const scrollToDay = useCallback((dayId: number) => {
const el = dayRefs.current.get(dayId)
const container = scrollContainerRef.current
if (!el || !container) return
// Positioned against the container, not scrollIntoView: the sidebar sits in
// a page that also scrolls, and scrollIntoView would drag the whole layout
// around to satisfy a scroll inside one column.
container.scrollTo({ top: el.offsetTop - container.offsetTop - 8, behavior: 'smooth' })
}, [])
const jumpToToday = useCallback(() => {
if (todayDayId == null) return
onSelectDay(todayDayId, true)
setExpandedDays(prev => new Set(prev).add(todayDayId))
// After the expand has rendered, or the target is measured at its old height.
requestAnimationFrame(() => scrollToDay(todayDayId))
}, [todayDayId, onSelectDay, scrollToDay])
// On opening a trip that is running, land on today rather than on day 1 (#1567).
// Once per mount, and only while nothing is selected yet: a deep link into a
// specific day, or a day the user picked before switching tabs, must win.
const autoJumpedRef = useRef(false)
useEffect(() => {
if (autoJumpedRef.current || todayDayId == null || selectedDayId != null || days.length === 0) return
autoJumpedRef.current = true
jumpToToday()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [todayDayId, days.length])
useLayoutEffect(() => {
if (scrollContainerRef.current && initialScrollTop) {
scrollContainerRef.current.scrollTop = initialScrollTop
@@ -1008,6 +1042,7 @@ function useDayPlanSidebar(props: DayPlanSidebarProps) {
setTimeConfirm,
dragDataRef,
scrollContainerRef,
dayRefs,
initedTransportIds,
lastAutoScrolledIdRef,
currency,
@@ -1181,6 +1216,7 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
setTimeConfirm,
dragDataRef,
scrollContainerRef,
dayRefs,
initedTransportIds,
lastAutoScrolledIdRef,
currency,
@@ -1339,7 +1375,8 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
return (
// The card wrapper stays untinted — its three regions (badge, header,
// activity list) paint themselves, so a plugin controls them separately.
<div key={day.id} title={dayTint?.label || undefined} style={{ borderBottom: '1px solid var(--border-faint)' }}>
<div key={day.id} ref={el => { if (el) dayRefs.current.set(day.id, el); else dayRefs.current.delete(day.id) }}
title={dayTint?.label || undefined} style={{ borderBottom: '1px solid var(--border-faint)' }}>
{/* Tages-Header — akzeptiert Drops aus der PlacesSidebar */}
<div
className="dp-day-header"
@@ -0,0 +1,46 @@
import { describe, it, expect } from 'vitest'
import { findTodayDayId, localToday } from './today'
describe('localToday', () => {
it('FE-TODAY-001: reads the date off the local clock, not UTC', () => {
// 08:00 in Tokyo on the 12th is still the 11th in UTC. Using toISOString()
// here would tell a traveller in Japan that today is yesterday, every
// morning, which is exactly who "jump to today" is for.
const tokyoMorning = new Date(2026, 7, 12, 8, 0, 0)
expect(localToday(tokyoMorning)).toBe('2026-08-12')
// And the other end: late evening must not roll over into tomorrow.
expect(localToday(new Date(2026, 7, 12, 23, 30, 0))).toBe('2026-08-12')
})
it('FE-TODAY-002: pads month and day to two digits', () => {
expect(localToday(new Date(2026, 0, 5, 12, 0, 0))).toBe('2026-01-05')
})
})
describe('findTodayDayId', () => {
const days = [
{ id: 1, date: '2026-08-10' },
{ id: 2, date: '2026-08-11' },
{ id: 3, date: '2026-08-12' },
]
const at = (y: number, m: number, d: number) => new Date(y, m - 1, d, 10, 0, 0)
it('FE-TODAY-003: finds the day that is today', () => {
expect(findTodayDayId(days, at(2026, 8, 11))).toBe(2)
})
it('FE-TODAY-004: is null when the trip is not running', () => {
expect(findTodayDayId(days, at(2026, 8, 9))).toBeNull()
expect(findTodayDayId(days, at(2026, 8, 13))).toBeNull()
expect(findTodayDayId([], at(2026, 8, 11))).toBeNull()
})
it('FE-TODAY-005: a trip planned without dates has no today to jump to', () => {
expect(findTodayDayId([{ id: 1, date: null }, { id: 2 }], at(2026, 8, 11))).toBeNull()
})
it('FE-TODAY-006: tolerates a full timestamp in the date column', () => {
expect(findTodayDayId([{ id: 7, date: '2026-08-11T00:00:00.000Z' }], at(2026, 8, 11))).toBe(7)
})
})
+30
View File
@@ -0,0 +1,30 @@
/**
* Finding "today" inside a trip (#1567).
*
* Deliberately local, not UTC. `new Date().toISOString()` is the obvious way to
* get a YYYY-MM-DD and it is wrong for exactly the people this feature is for:
* someone in Tokyo opening the planner at 08:00 gets yesterday's date, and
* someone in Los Angeles at 17:00 gets tomorrow's. A trip day is a calendar day
* where the traveller is standing, so the comparison has to be made in their
* own clock.
*/
/** Today as YYYY-MM-DD in the viewer's own timezone. */
export function localToday(now: Date = new Date()): string {
const pad = (n: number) => String(n).padStart(2, '0')
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`
}
/**
* The id of the day that is today, or null when the trip is not running.
*
* Days without a date (a trip planned as "day 1..7" with no calendar attached)
* can never match, which is the intended outcome: there is nothing to jump to.
*/
export function findTodayDayId(days: Array<{ id: number; date?: string | null }>, now?: Date): number | null {
const today = localToday(now)
// Only the date part: the column is a date, but a caller could hand over an
// ISO timestamp and a trip would silently stop having a "today".
const match = days.find(d => typeof d.date === 'string' && d.date.slice(0, 10) === today)
return match ? match.id : null
}