Skip to content

Commit

Permalink
fix(app): departures fetching logic
Browse files Browse the repository at this point in the history
  • Loading branch information
krystxf committed Nov 16, 2024
1 parent 04ae847 commit 4954a3d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class ClosestStopListViewModel: NSObject, ObservableObject, CLLocationManagerDel
parameters: [
"stop": stopsIds,
"limit": 20,
"totalLimit": 80,
"minutesBefore": 1,
"minutesAfter": String(5 * 60),
]
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// metro-now
// https://github.com/krystxf/metro-now


import SwiftUI

struct ClosestStopListView: View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [])
Expand Down Expand Up @@ -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)"
)
}
Expand All @@ -145,6 +144,7 @@ class ClosestStopPageViewModel: NSObject, ObservableObject, CLLocationManagerDel
"platform": platformsIds,
"limit": 4,
"minutesBefore": 1,
"minutesAfter": String(3 * 60),
]
)

Expand All @@ -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 {
Expand Down

0 comments on commit 4954a3d

Please sign in to comment.