@@ -58,6 +58,7 @@ struct PushNotificationListFeature {
5858 case loading( LoadingFeature . Action )
5959
6060 enum ViewAction : Equatable {
61+ case refresh
6162 case fetchNotifications
6263 case loadNextPage
6364 case deleteNotification( PushNotificationItem )
@@ -83,7 +84,6 @@ struct PushNotificationListFeature {
8384 case syncNotifications( [ PushNotificationItem ] , nextCursor: PushNotificationCursor ? , hasMore: Bool )
8485 case setNotificationHidden( String , Bool )
8586 case setNotificationRead( String , Bool )
86- case observeNotifications( PushNotificationQuery , Int )
8787 }
8888 }
8989
@@ -151,6 +151,9 @@ private extension PushNotificationListFeature {
151151 state: inout State
152152 ) -> Effect < Action > {
153153 switch action {
154+ case . refresh:
155+ state. nextCursor = nil
156+ return fetchNotificationsPageEffect ( query: state. query, cursor: nil )
154157 case . fetchNotifications:
155158 state. nextCursor = nil
156159 return fetchNotificationsEffect ( query: state. query, cursor: nil , existingCount: 0 )
@@ -252,8 +255,6 @@ private extension PushNotificationListFeature {
252255 if let index = state. notifications. firstIndex ( where: { $0. id == notificationId } ) {
253256 state. notifications [ index] . isRead = isRead
254257 }
255- case . observeNotifications( let query, let limit) :
256- return observeNotificationsEffect ( query: query, limit: limit)
257258 }
258259
259260 return . none
@@ -272,7 +273,28 @@ private extension PushNotificationListFeature {
272273 existingCount: Int
273274 ) -> Effect < Action > {
274275 let limit = max ( query. pageSize, existingCount)
275- let fetchEffect : Effect < Action > = . run { [ fetchPushNotificationsUseCase] send in
276+ let fetchEffect = fetchNotificationsPageEffect ( query: query, cursor: cursor)
277+ let observeEffect = observeNotificationsEffect (
278+ query: query,
279+ limit: max ( limit, existingCount + query. pageSize)
280+ )
281+
282+ if cursor == nil {
283+ return . concatenate(
284+ . cancel( id: CancelID . observeNotifications) ,
285+ fetchEffect,
286+ observeEffect
287+ )
288+ }
289+
290+ return fetchEffect
291+ }
292+
293+ func fetchNotificationsPageEffect(
294+ query: PushNotificationQuery ,
295+ cursor: PushNotificationCursor ?
296+ ) -> Effect < Action > {
297+ . run { [ fetchPushNotificationsUseCase] send in
276298 await send ( . loading( . begin( target: . default, mode: . delayed) ) )
277299 do {
278300 let page = try await fetchPushNotificationsUseCase. execute ( query, cursor: cursor)
@@ -286,23 +308,13 @@ private extension PushNotificationListFeature {
286308 ) )
287309 )
288310 await send ( . store( . setHasMore( page. items. count == query. pageSize && page. nextCursor != nil ) ) )
289- await send ( . store( . observeNotifications( query, max ( limit, existingCount + page. items. count) ) ) )
290311 await send ( . loading( . end( target: . default, mode: . delayed) ) )
291312 } catch {
292313 await send ( . loading( . end( target: . default, mode: . delayed) ) )
293314 await send ( . store( . setAlert) )
294315 }
295316 }
296317 . cancellable ( id: CancelID . fetchNotifications, cancelInFlight: true )
297-
298- if cursor == nil {
299- return . concatenate(
300- . cancel( id: CancelID . observeNotifications) ,
301- fetchEffect
302- )
303- }
304-
305- return fetchEffect
306318 }
307319
308320 func observeNotificationsEffect(
0 commit comments