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
+2 -13
View File
@@ -7,6 +7,7 @@
import type { Trip } from '../../types'
import { localIsoDate } from '../../utils/localDate'
import { sortTripsByRelevance } from '../../utils/heroTrip'
// The dashboard works with the canonical Trip shape returned by the list/get
// endpoints (it already carries the computed day_count/place_count/is_owner/
@@ -83,17 +84,5 @@ export function getTripStatus(trip: DashboardTrip): 'ongoing' | 'today' | 'tomor
}
export function sortTrips(trips: DashboardTrip[]): DashboardTrip[] {
const today = localIsoToday()
const rank = (t: DashboardTrip) => {
if (t.start_date && t.end_date && t.start_date <= today && t.end_date >= today) return 0
if (t.start_date && t.start_date >= today) return 1
return 2
}
return [...trips].sort((a, b) => {
const ra = rank(a), rb = rank(b)
if (ra !== rb) return ra - rb
const ad = a.start_date || '', bd = b.start_date || ''
if (ra <= 1) return ad.localeCompare(bd)
return bd.localeCompare(ad)
})
return sortTripsByRelevance(trips, localIsoToday())
}
+2 -3
View File
@@ -9,6 +9,7 @@ import { useTranslation } from '../../i18n'
import { useToast } from '../../components/shared/Toast'
import { getApiErrorMessage } from '../../types'
import { localIsoToday } from './dashboardModel'
import { heroTrip } from '../../utils/heroTrip'
import { useTripSearch } from './useTripSearch'
import type { TripCreateRequest } from '@trek/shared'
import {
@@ -120,9 +121,7 @@ export function useDashboard() {
// A trip the hero features on its own merit: one that is running, else the next
// one coming up. Only that one is taken out of the grid below, so the same trip
// isn't shown twice.
const featured = trips.find(t => t.start_date && t.end_date && t.start_date <= today && t.end_date >= today)
|| trips.find(t => t.start_date && t.start_date >= today)
|| null
const featured = heroTrip(trips, today)
// With neither, the hero still shows something rather than sitting empty — but
// that trip is only borrowed for the header and must stay in the grid, or a user
// whose trips are all finished (or undated) sees "No trips yet". #1706