diff --git a/DevLog/Presentation/ViewModel/PushNotificationViewModel.swift b/DevLog/Presentation/ViewModel/PushNotificationListViewModel.swift similarity index 95% rename from DevLog/Presentation/ViewModel/PushNotificationViewModel.swift rename to DevLog/Presentation/ViewModel/PushNotificationListViewModel.swift index ed6c29a..a745180 100644 --- a/DevLog/Presentation/ViewModel/PushNotificationViewModel.swift +++ b/DevLog/Presentation/ViewModel/PushNotificationListViewModel.swift @@ -1,5 +1,5 @@ // -// PushNotificationViewModel.swift +// PushNotificationListViewModel.swift // DevLog // // Created by 최윤진 on 11/22/25. @@ -7,7 +7,7 @@ import Foundation -final class PushNotificationViewModel: Store { +final class PushNotificationListViewModel: Store { struct State { var notifications: [PushNotification] = [] var showAlert: Bool = false @@ -157,7 +157,7 @@ final class PushNotificationViewModel: Store { } // MARK: - Reduce Methods -private extension PushNotificationViewModel { +private extension PushNotificationListViewModel { func reduceByUser(_ action: Action, state: inout State) -> [SideEffect] { switch action { case .deleteNotification(let item): @@ -197,8 +197,12 @@ private extension PushNotificationViewModel { updateQueryUseCase.execute(state.query) state.nextCursor = nil return [.fetchNotifications(state.query, cursor: nil)] - case .tapNotification(let notification): - state.selectedTodoID = TodoIDItem(id: notification.todoID) + case .tapNotification(let item): + state.selectedTodoID = TodoIDItem(id: item.todoID) + if let index = state.notifications.firstIndex(where: { $0.id == item.id }), !item.isRead { + state.notifications[index].isRead.toggle() + return [.toggleRead(item.todoID)] + } default: break } @@ -252,7 +256,7 @@ private extension PushNotificationViewModel { } } -private extension PushNotificationViewModel { +private extension PushNotificationListViewModel { func setAlert( _ state: inout State, isPresented: Bool, diff --git a/DevLog/UI/Common/MainView.swift b/DevLog/UI/Common/MainView.swift index c4e30a3..3733932 100644 --- a/DevLog/UI/Common/MainView.swift +++ b/DevLog/UI/Common/MainView.swift @@ -23,7 +23,7 @@ struct MainView: View { Image(systemName: "house.fill") Text("홈") } - PushNotificationView(viewModel: PushNotificationViewModel( + PushNotificationListView(viewModel: PushNotificationListViewModel( fetchUseCase: container.resolve(FetchPushNotificationsUseCase.self), deleteUseCase: container.resolve(DeletePushNotificationUseCase.self), toggleReadUseCase: container.resolve(TogglePushNotificationReadUseCase.self), diff --git a/DevLog/UI/PushNotification/PushNotificationView.swift b/DevLog/UI/PushNotification/PushNotificationListView.swift similarity index 98% rename from DevLog/UI/PushNotification/PushNotificationView.swift rename to DevLog/UI/PushNotification/PushNotificationListView.swift index 0bd84b1..d2ec1af 100644 --- a/DevLog/UI/PushNotification/PushNotificationView.swift +++ b/DevLog/UI/PushNotification/PushNotificationListView.swift @@ -1,5 +1,5 @@ // -// PushNotificationView.swift +// PushNotificationListView.swift // DevLog // // Created by opfic on 5/14/25. @@ -7,9 +7,9 @@ import SwiftUI -struct PushNotificationView: View { +struct PushNotificationListView: View { @StateObject private var router = NavigationRouter() - @StateObject var viewModel: PushNotificationViewModel + @StateObject var viewModel: PushNotificationListViewModel @Environment(\.sceneWidth) private var sceneWidth @Environment(\.colorScheme) private var colorScheme @Environment(\.diContainer) private var container: DIContainer