fix(native): the widgets show the trip the dashboard features

With several trips running at once, the widgets took whichever came first
on the device, so an old test trip spanning today pushed out the journey
under way, and the today widget counted its days. The dashboard's choice
moves to utils/heroTrip.ts (running first, earliest start, else the next to
come) and the widgets ask the same function, so the home screen always
shows the trip the app opens on.
This commit is contained in:
Maurice
2026-11-06 20:25:41 +01:00
parent 6b8eb939c3
commit ae082c1fd0
6 changed files with 81 additions and 25 deletions
+9
View File
@@ -51,6 +51,15 @@ describe('pickTrip', () => {
expect(pickTrip(trips, '2026-11-12')?.id).toBe(2);
});
it('of several running trips takes the dashboard hero: the one that started first', () => {
const trips = [
trip(1, '2026-11-02', '2026-11-06'),
trip(2, '2026-10-20', '2026-11-18'),
trip(3, '2026-11-04', '2026-11-12'),
];
expect(pickTrip(trips, '2026-11-06')?.id).toBe(2);
});
it('skips undated, archived and finished trips', () => {
expect(
pickTrip(
+6 -9
View File
@@ -1,5 +1,6 @@
import type { Day, Reservation, Trip } from '../types';
import { splitReservationDateTime } from '../utils/formatters';
import { heroTrip, sortTripsByRelevance } from '../utils/heroTrip';
import { hasNativeFeature } from './capabilities';
import { isNativeIos } from './platform';
import { reportNativeFailure } from './reportFailure';
@@ -121,17 +122,13 @@ function minutesOf(time: string | null | undefined): number | null {
}
/**
* The running trip if there is one, else the next to start. Trips without dates
* and trips already over are not candidates.
* The trip the dashboard's hero features (utils/heroTrip.ts): the running one,
* else the next to start, so the widgets show the trip the app opens on.
* Archived trips are not candidates, as on the dashboard.
*/
export function pickTrip(trips: Trip[], today: string): Trip | null {
const dated = trips.flatMap((t) =>
t.start_date && t.end_date && !t.is_archived ? [{ trip: t, start: t.start_date, end: t.end_date }] : []
);
const running = dated.find((d) => d.start <= today && d.end >= today);
if (running) return running.trip;
const upcoming = dated.filter((d) => d.start > today).sort((a, b) => a.start.localeCompare(b.start));
return upcoming[0]?.trip ?? null;
const active = trips.filter((t) => !t.is_archived);
return heroTrip(sortTripsByRelevance(active, today), today);
}
/** The symbols of the booking kinds a day's timeline shows next to its stops. */