@@ -80,10 +80,13 @@ public let eventReducer = Reducer<EventsState, EventsAction, EventsEnvironment>
80
80
}
81
81
82
82
var fetchEvents : Effect < EventsAction , Never > {
83
- guard state. isConnected, let location = state. location else { return . none }
84
- state. location = location
83
+ guard state. isConnected && state. canLoadMorePages,
84
+ let location = state. location
85
+ else {
86
+ return . none
87
+ }
85
88
86
- guard state. canLoadMorePages else { return . none }
89
+ state. location = location
87
90
88
91
let getDistanceType = environment. userDefaults. integerForKey ( " typee " )
89
92
let maxDistance = getDistanceType == 0 ? ( 250 * 1000 ) : ( 250 / 1.609 ) * 1609
@@ -122,11 +125,11 @@ public let eventReducer = Reducer<EventsState, EventsAction, EventsEnvironment>
122
125
. map ( EventsAction . eventsResponse)
123
126
}
124
127
125
- func getLocation ( _ location: Location ) -> Effect < EventsAction , Never > {
126
- return environment. getCoordinate ( location)
128
+ func getPlacemark ( _ location: Location ) -> Effect < EventsAction , Never > {
129
+ return environment. getPlacemark ( location)
127
130
. receive ( on: environment. mainQueue)
128
131
. catchToEffect ( )
129
- . map ( EventsAction . eventCoordinate )
132
+ . map ( EventsAction . eventPlacemarkResponse )
130
133
}
131
134
132
135
func presentChatView( ) -> Effect < EventsAction , Never > {
@@ -139,6 +142,7 @@ public let eventReducer = Reducer<EventsState, EventsAction, EventsEnvironment>
139
142
140
143
switch action {
141
144
case . onAppear:
145
+
142
146
let status = environment. locationManager. authorizationStatus ( )
143
147
if status == . authorizedAlways || status == . authorizedWhenInUse {
144
148
return fetchEvents
@@ -205,7 +209,7 @@ public let eventReducer = Reducer<EventsState, EventsAction, EventsEnvironment>
205
209
case let . addressResponse( . success( address) ) :
206
210
return . none
207
211
208
- case let . eventCoordinate ( . success( placemark) ) :
212
+ case let . eventPlacemarkResponse ( . success( placemark) ) :
209
213
let formatter = CNPostalAddressFormatter ( )
210
214
guard let postalAddress = placemark. postalAddress else {
211
215
// handle error here
@@ -218,14 +222,13 @@ public let eventReducer = Reducer<EventsState, EventsAction, EventsEnvironment>
218
222
return . none
219
223
220
224
case let . locationManager( . didUpdateLocations( locations) ) :
221
-
225
+ state . isLoadingPage = true
222
226
guard state. isConnected, let location = locations. first else { return . none }
223
227
state. location = location
224
228
225
- state. isLoadingPage = true
226
229
return . merge(
227
230
fetchEvents,
228
- getLocation ( location)
231
+ getPlacemark ( location)
229
232
)
230
233
231
234
case . locationManager:
0 commit comments