mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 14:17:31 +00:00
fix(widgets): keep every stop of the day the snapshot was written on
The days ahead keep only their first 16 stops, and the widget read today from that list too, so on a busy day it showed the wrong next stop. The full day the app wrote now stays in place on its own date.
This commit is contained in:
@@ -44,7 +44,7 @@ data class WidgetSnapshot(
|
||||
if (days.isEmpty()) return this
|
||||
val key = date.toString()
|
||||
return copy(
|
||||
today = days.firstOrNull { it.date == key },
|
||||
today = if (today?.date == key) today else days.firstOrNull { it.date == key },
|
||||
bookings = bookings.filter { (it.date ?: key) >= key },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -123,6 +123,21 @@ class WidgetSnapshotTest {
|
||||
assertNull(snapshot.on(LocalDate.of(2026, 11, 9)).today)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun keepsEveryStopOfTheDayItWasWrittenOn() {
|
||||
val json = """{"trip":{"title":"T","start":"2026-11-06","end":"2026-11-07","path":"/trips/1"},
|
||||
"today":{"date":"2026-11-06","dayLabel":"Day 1 of 2","stops":[
|
||||
{"time":"09:00","name":"Museum","minutes":540},{"time":"21:00","name":"Concert","minutes":1260}]},
|
||||
"days":[
|
||||
{"date":"2026-11-06","dayLabel":"Day 1 of 2","stops":[{"time":"09:00","name":"Museum","minutes":540}]},
|
||||
{"date":"2026-11-07","dayLabel":"Day 2 of 2","stops":[{"time":"10:00","name":"Harbour","minutes":600}]}
|
||||
],
|
||||
"labels":{}}"""
|
||||
val snapshot = WidgetSnapshot.parse(json)!!
|
||||
assertEquals(listOf("Museum", "Concert"), snapshot.on(LocalDate.of(2026, 11, 6)).today!!.stops.map { it.name })
|
||||
assertEquals("Day 2 of 2", snapshot.on(LocalDate.of(2026, 11, 7)).today!!.dayLabel)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSnapshotWithoutDaysReadsAsWritten() {
|
||||
val snapshot = WidgetSnapshot.parse(WidgetSamples.json(running = true, now = today))!!
|
||||
|
||||
@@ -320,7 +320,7 @@ struct WidgetSnapshot: Codable {
|
||||
guard let days, !days.isEmpty else { return self }
|
||||
let key = WidgetSnapshot.key(date)
|
||||
var snapshot = self
|
||||
snapshot.today = days.first { $0.date == key }
|
||||
if today?.date != key { snapshot.today = days.first { $0.date == key } }
|
||||
snapshot.bookings = bookings?.filter { ($0.date ?? key) >= key }
|
||||
return snapshot
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user