From 4954a3d22e2820d14c27a415a49ec3fa4f3a8c86 Mon Sep 17 00:00:00 2001 From: Krystof Date: Sun, 17 Nov 2024 00:42:02 +0100 Subject: [PATCH] fix(app): departures fetching logic --- .../components/countdown-view/countdown.swift | 19 +++++++------- .../closest-stop-list-view-model.swift | 2 +- .../closest-stop-list.view.swift | 1 - .../closest-stop-page-view-model.swift | 26 ++++++++++++------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/apps/mobile/metro-now/common/components/countdown-view/countdown.swift b/apps/mobile/metro-now/common/components/countdown-view/countdown.swift index feded45..f03a23d 100644 --- a/apps/mobile/metro-now/common/components/countdown-view/countdown.swift +++ b/apps/mobile/metro-now/common/components/countdown-view/countdown.swift @@ -23,16 +23,15 @@ struct CountdownView: View { } var body: some View { - Text( - customFunction( - getRemainingTime( - timeRemaining - ) - ) - ) - .onReceive(timer) { _ in - updateRemainingTime() - } + Text(customFunction(getRemainingTime(timeRemaining))) + #if os(watchOS) + .fontDesign(.default) // is more readable on watch IMO + #else + .fontDesign(.monospaced) // prevents letter shifts + #endif + .onReceive(timer) { _ in + updateRemainingTime() + } } private func updateRemainingTime() { diff --git a/apps/mobile/metro-now/metro-now Watch App/pages/closest-stop-list/closest-stop-list-view-model.swift b/apps/mobile/metro-now/metro-now Watch App/pages/closest-stop-list/closest-stop-list-view-model.swift index 220d36c..8ea7f5e 100644 --- a/apps/mobile/metro-now/metro-now Watch App/pages/closest-stop-list/closest-stop-list-view-model.swift +++ b/apps/mobile/metro-now/metro-now Watch App/pages/closest-stop-list/closest-stop-list-view-model.swift @@ -109,8 +109,8 @@ class ClosestStopListViewModel: NSObject, ObservableObject, CLLocationManagerDel parameters: [ "stop": stopsIds, "limit": 20, - "totalLimit": 80, "minutesBefore": 1, + "minutesAfter": String(5 * 60), ] ) diff --git a/apps/mobile/metro-now/metro-now Watch App/pages/closest-stop-list/closest-stop-list.view.swift b/apps/mobile/metro-now/metro-now Watch App/pages/closest-stop-list/closest-stop-list.view.swift index beb2afe..245c794 100644 --- a/apps/mobile/metro-now/metro-now Watch App/pages/closest-stop-list/closest-stop-list.view.swift +++ b/apps/mobile/metro-now/metro-now Watch App/pages/closest-stop-list/closest-stop-list.view.swift @@ -1,7 +1,6 @@ // metro-now // https://github.com/krystxf/metro-now - import SwiftUI struct ClosestStopListView: View { diff --git a/apps/mobile/metro-now/metro-now/pages/closest-stop/closest-stop-page-view-model.swift b/apps/mobile/metro-now/metro-now/pages/closest-stop/closest-stop-page-view-model.swift index 6dbb5a5..d22f263 100644 --- a/apps/mobile/metro-now/metro-now/pages/closest-stop/closest-stop-page-view-model.swift +++ b/apps/mobile/metro-now/metro-now/pages/closest-stop/closest-stop-page-view-model.swift @@ -79,19 +79,17 @@ class ClosestStopPageViewModel: NSObject, ObservableObject, CLLocationManagerDel return } - if - let metroStops, - let nextValue = findClosestStop(to: location, stops: metroStops), - nextValue.id != self.closestMetroStop?.id + if let metroStops, + let nextValue = findClosestStop(to: location, stops: metroStops), + nextValue.id != self.closestMetroStop?.id { closestMetroStop = nextValue getDepartures(stopsIds: [nextValue.id], platformsIds: []) } - if - let allStops, - let nextValue = findClosestStop(to: location, stops: allStops), - nextValue.id != self.closestStop?.id + if let allStops, + let nextValue = findClosestStop(to: location, stops: allStops), + nextValue.id != self.closestStop?.id { closestStop = nextValue getDepartures(stopsIds: [nextValue.id], platformsIds: []) @@ -123,7 +121,8 @@ class ClosestStopPageViewModel: NSObject, ObservableObject, CLLocationManagerDel } case let .failure(error): print( - metroOnly ? "Error fetching metroStops: \(error)" + metroOnly + ? "Error fetching metroStops: \(error)" : "Error fetching stops: \(error)" ) } @@ -145,6 +144,7 @@ class ClosestStopPageViewModel: NSObject, ObservableObject, CLLocationManagerDel "platform": platformsIds, "limit": 4, "minutesBefore": 1, + "minutesAfter": String(3 * 60), ] ) @@ -155,8 +155,14 @@ class ClosestStopPageViewModel: NSObject, ObservableObject, CLLocationManagerDel case let .success(fetchedDepartures): DispatchQueue.main.async { if let oldDepartures = self.departures { + let oldStuff = oldDepartures.filter { oldDeparture in + !fetchedDepartures.contains(where: { fetchedDeparture in + fetchedDeparture.id == oldDeparture.id + + }) + } self.departures = uniqueBy( - array: oldDepartures + fetchedDepartures, + array: oldStuff + fetchedDepartures, by: \.id ) .filter {