|
1 | 1 | // |
2 | | -// PushNotificationViewModel.swift |
| 2 | +// PushNotificationListViewModel.swift |
3 | 3 | // DevLog |
4 | 4 | // |
5 | 5 | // Created by 최윤진 on 11/22/25. |
6 | 6 | // |
7 | 7 |
|
8 | 8 | import Foundation |
9 | 9 |
|
10 | | -final class PushNotificationViewModel: Store { |
| 10 | +final class PushNotificationListViewModel: Store { |
11 | 11 | struct State { |
12 | 12 | var notifications: [PushNotification] = [] |
13 | 13 | var showAlert: Bool = false |
@@ -157,7 +157,7 @@ final class PushNotificationViewModel: Store { |
157 | 157 | } |
158 | 158 |
|
159 | 159 | // MARK: - Reduce Methods |
160 | | -private extension PushNotificationViewModel { |
| 160 | +private extension PushNotificationListViewModel { |
161 | 161 | func reduceByUser(_ action: Action, state: inout State) -> [SideEffect] { |
162 | 162 | switch action { |
163 | 163 | case .deleteNotification(let item): |
@@ -197,8 +197,12 @@ private extension PushNotificationViewModel { |
197 | 197 | updateQueryUseCase.execute(state.query) |
198 | 198 | state.nextCursor = nil |
199 | 199 | return [.fetchNotifications(state.query, cursor: nil)] |
200 | | - case .tapNotification(let notification): |
201 | | - state.selectedTodoID = TodoIDItem(id: notification.todoID) |
| 200 | + case .tapNotification(let item): |
| 201 | + state.selectedTodoID = TodoIDItem(id: item.todoID) |
| 202 | + if let index = state.notifications.firstIndex(where: { $0.id == item.id }), !item.isRead { |
| 203 | + state.notifications[index].isRead.toggle() |
| 204 | + return [.toggleRead(item.todoID)] |
| 205 | + } |
202 | 206 | default: |
203 | 207 | break |
204 | 208 | } |
@@ -252,7 +256,7 @@ private extension PushNotificationViewModel { |
252 | 256 | } |
253 | 257 | } |
254 | 258 |
|
255 | | -private extension PushNotificationViewModel { |
| 259 | +private extension PushNotificationListViewModel { |
256 | 260 | func setAlert( |
257 | 261 | _ state: inout State, |
258 | 262 | isPresented: Bool, |
|
0 commit comments