Skip to content

Commit 01c049d

Browse files
committed
fix: 토스트 UI 롤백에 의한 pendingTask 해결
1 parent 35d38aa commit 01c049d

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

DevLog/Presentation/ViewModel/PushNotificationViewModel.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,11 @@ private extension PushNotificationViewModel {
216216
state.nextCursor = nil
217217
return [.fetchNotifications(state.query, cursor: nil)]
218218
case .loadNextPage:
219-
guard state.hasMore, !state.isLoading else { return [] }
219+
guard state.hasMore, !state.isLoading, state.pendingTask == nil else { return [] }
220220
return [.fetchNotifications(state.query, cursor: state.nextCursor)]
221221
case .confirmDelete:
222-
guard let (item, _ ) = state.pendingTask else { return [] }
222+
guard let (item, _) = state.pendingTask else { return [] }
223+
state.pendingTask = nil
223224
return [.delete(item)]
224225
case .setToast(let isPresented, let type):
225226
setToast(&state, isPresented: isPresented, for: type)
@@ -241,7 +242,13 @@ private extension PushNotificationViewModel {
241242
state.notifications = []
242243
state.nextCursor = nil
243244
case .appendNotifications(let notifications, let nextCursor):
244-
state.notifications.append(contentsOf: notifications)
245+
let filteredNotifications: [PushNotification]
246+
if let (pendingItem, _) = state.pendingTask {
247+
filteredNotifications = notifications.filter { $0.id != pendingItem.id }
248+
} else {
249+
filteredNotifications = notifications
250+
}
251+
state.notifications.append(contentsOf: filteredNotifications)
245252
state.nextCursor = nextCursor
246253
default:
247254
break

0 commit comments

Comments
 (0)