Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

feat(dawarich): preselect the stay's day in the accept dialog (#3068)

Maurice11e4fe6ae349
diff --git a/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx b/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx
index d409c3629..c4baaa362 100644
--- a/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx
+++ b/client/src/components/Dawarich/DawarichAcceptDialog.test.tsx
@@ -1,4 +1,4 @@
-// FE-DAWARICH-ACCEPT-001 to FE-DAWARICH-ACCEPT-026
+// FE-DAWARICH-ACCEPT-001 to FE-DAWARICH-ACCEPT-029
/**
* The review step between a detector's guess and a row in somebody's trip.
*
@@ -95,6 +95,20 @@ const DAYS: Record<number, AcceptTargetOption[]> = {
}
const daysForTrip = (tripId: number): AcceptTargetOption[] => DAYS[tripId] ?? []
+// The same trips with their calendar dates, as the planner hands them over: the
+// stay fell on 10 Sept, which is day 2 of the Rhineland trip and day 1 of a
+// second trip that started that morning.
+const DATED_DAYS: Record<number, AcceptTargetOption[]> = {
+ 31: [
+ { id: 401, label: 'Day 1', badge: '09 Sept', date: '2026-09-09' },
+ { id: 402, label: 'Day 2', badge: '10 Sept', date: '2026-09-10' },
+ ],
+ 32: [{ id: 501, label: 'Alpine day', badge: '10 Sept', date: '2026-09-10' }],
+ 33: [{ id: 601, label: 'Coast day', badge: '01 Oct', date: '2026-10-01' }],
+}
+const datedDaysForTrip = (tripId: number): AcceptTargetOption[] => DATED_DAYS[tripId] ?? []
+const DATED_TRIPS: AcceptTargetOption[] = [...TRIPS, { id: 33, label: 'Coast' }]
+
const JOURNALS: AcceptTargetOption[] = [
{ id: 71, label: 'Rhine notebook' },
{ id: 72, label: 'Alpine notebook' },
@@ -565,4 +579,49 @@ describe('DawarichAcceptDialog', () => {
fireEvent.click(screen.getByRole('button', { name: 'Add place' }))
expect(onConfirm).toHaveBeenLastCalledWith({ target: 'place', tripId: 31, time: '10:15', endTime: '12:40' })
})
+
+ it('FE-DAWARICH-ACCEPT-027: the day picker opens on the trip day the stay was recorded on (#3068)', () => {
+ const { onConfirm } = open({ trips: DATED_TRIPS, daysForTrip: datedDaysForTrip })
+
+ // Day 2 is 10 Sept, the stay's own local date: accepting with the defaults
+ // files the place where it was actually visited.
+ expect(screen.getByRole('button', { name: /Day 2/ })).toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: 'Add place' }))
+ expect(onConfirm).toHaveBeenCalledWith({ target: 'place', tripId: 31, dayId: 402, time: '10:15', endTime: '12:40' })
+ })
+
+ it("FE-DAWARICH-ACCEPT-028: switching the trip moves the preselection to that trip's day, or to none", () => {
+ const { onConfirm } = open({ trips: DATED_TRIPS, daysForTrip: datedDaysForTrip })
+
+ pick('Rhineland', 'Alps')
+ expect(screen.getByRole('button', { name: /Alpine day/ })).toBeInTheDocument()
+
+ // The coast trip has no day on 10 Sept, so nothing is guessed for it.
+ pick('Alps', 'Coast')
+ expect(screen.getByRole('button', { name: 'Not on a day yet' })).toBeInTheDocument()
+
+ fireEvent.click(screen.getByRole('button', { name: 'Add place' }))
+ expect(onConfirm).toHaveBeenCalledWith({ target: 'place', tripId: 33, time: '10:15', endTime: '12:40' })
+ })
+
+ it('FE-DAWARICH-ACCEPT-029: a preselected day can still be undone, and a new stay is matched afresh', () => {
+ const { onConfirm, update } = open({ trips: DATED_TRIPS, daysForTrip: datedDaysForTrip })
+
+ // Unplanned stays a deliberate answer next to the preselection.
+ pick(/Day 2/, 'Not on a day yet')
+ fireEvent.click(screen.getByRole('button', { name: 'Add place' }))
+ expect(onConfirm).toHaveBeenLastCalledWith({ target: 'place', tripId: 31, time: '10:15', endTime: '12:40' })
+
+ // The next stay fell on the 9th: its own day, not the one cleared above.
+ update({
+ suggestion: stay({
+ id: 4,
+ localDate: '2026-09-09',
+ startedAt: '2026-09-09T10:15:00+02:00',
+ endedAt: '2026-09-09T12:40:00+02:00',
+ }),
+ })
+ fireEvent.click(screen.getByRole('button', { name: 'Add place' }))
+ expect(onConfirm).toHaveBeenLastCalledWith({ target: 'place', tripId: 31, dayId: 401, time: '10:15', endTime: '12:40' })
+ })
})
diff --git a/client/src/components/Dawarich/DawarichAcceptDialog.tsx b/client/src/components/Dawarich/DawarichAcceptDialog.tsx
index 985c7196a..c2571d1f1 100644
--- a/client/src/components/Dawarich/DawarichAcceptDialog.tsx
+++ b/client/src/components/Dawarich/DawarichAcceptDialog.tsx
@@ -19,6 +19,8 @@ export interface AcceptTargetOption {
label: string
/** Secondary half of the label — a day's date beside its number. */
badge?: string
+ /** A day's ISO date, so the day the stay fell on can be preselected (#3068). */
+ date?: string
}
export interface DawarichAcceptDialogProps {
@@ -81,6 +83,14 @@ export default function DawarichAcceptDialog({
// always describe the row the user just pressed rather than the previous one.
const [seededFor, setSeededFor] = useState<number | null>(null)
+ // The stay already knows the date it was recorded on, so the day picker opens
+ // on the trip day that matches it (#3068). Without one it stays unplanned:
+ // a guessed day would be worse than none.
+ function dayOfStay(forTrip: number | '', localDate: string): number | '' {
+ if (typeof forTrip !== 'number' || !daysForTrip) return ''
+ return daysForTrip(forTrip).find(day => day.date === localDate)?.id ?? ''
+ }
+
if (suggestion && seededFor !== suggestion.id) {
setSeededFor(suggestion.id)
setName(suggestion.name)
@@ -88,8 +98,9 @@ export default function DawarichAcceptDialog({
setDate(suggestion.localDate)
setTime(clockOf(suggestion.startedAt))
setEndTime(clockOf(suggestion.endedAt))
- setTripId(suggestion.tripId ?? (trips[0]?.id ?? ''))
- setDayId('')
+ const seededTrip = suggestion.tripId ?? (trips[0]?.id ?? '')
+ setTripId(seededTrip)
+ setDayId(dayOfStay(seededTrip, suggestion.localDate))
setJournalId(journals[0]?.id ?? '')
}
@@ -272,7 +283,13 @@ export default function DawarichAcceptDialog({
</span>
<CustomSelect
value={tripId}
- onChange={next => { setTripId(typeof next === 'number' ? next : ''); setDayId('') }}
+ onChange={next => {
+ const nextTrip = typeof next === 'number' ? next : ''
+ setTripId(nextTrip)
+ // The old day belongs to the old trip; the new trip's own day
+ // for the stay takes its place, if it has one.
+ setDayId(dayOfStay(nextTrip, suggestion.localDate))
+ }}
options={trips.map(trip => ({ value: trip.id, label: trip.label }))}
placeholder={t('dawarich.accept.pickTrip')}
style={{ width: '100%' }}
diff --git a/client/src/components/Planner/PlacesSidebar.tsx b/client/src/components/Planner/PlacesSidebar.tsx
index 45aec1b19..e125621f3 100644
--- a/client/src/components/Planner/PlacesSidebar.tsx
+++ b/client/src/components/Planner/PlacesSidebar.tsx
@@ -60,6 +60,7 @@ const PlacesSidebar = React.memo(function PlacesSidebar(props: PlacesSidebarProp
daysForTrip={() => days.map(day => ({
id: day.id,
...formatDayOption(day.day_number, day.date, locale, t),
+ date: day.date ?? undefined,
}))}
// The place it just created belongs on the map and in the list
// now, not after a reload.
diff --git a/client/src/mobile/screens/trip/places/MPlacesBrowser.tsx b/client/src/mobile/screens/trip/places/MPlacesBrowser.tsx
index 333192148..2c7a12d12 100644
--- a/client/src/mobile/screens/trip/places/MPlacesBrowser.tsx
+++ b/client/src/mobile/screens/trip/places/MPlacesBrowser.tsx
@@ -243,6 +243,7 @@ export default function MPlacesBrowser({ planner, shell }: MPlacesBrowserProps)
daysForTrip={() => days.map(day => ({
id: day.id,
...formatDayOption(day.day_number, day.date, locale, t),
+ date: day.date ?? undefined,
}))}
// The place it just created belongs on the map and in the list
// now, not after a reload.