Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// PushNotificationViewModel.swift
// PushNotificationListViewModel.swift
// DevLog
//
// Created by 최윤진 on 11/22/25.
//

import Foundation

final class PushNotificationViewModel: Store {
final class PushNotificationListViewModel: Store {
struct State {
var notifications: [PushNotification] = []
var showAlert: Bool = false
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)]
}
Comment on lines +202 to +205
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

현재 구현에서는 이미 읽은 알림을 탭하면 아무 동작도 하지 않습니다. 사용자가 알림을 탭하는 것은 읽음 상태와 관계없이 관련 내용을 확인하려는 의도일 가능성이 높으므로, 항상 상세 화면으로 이동하도록 하는 것이 좋습니다.

또한, item.isRead를 확인하는 대신 state.notifications[index].isRead를 확인하여 상태의 일관성을 보장하는 것이 더 안전합니다. item은 View가 생성될 때의 스냅샷일 수 있기 때문입니다.

따라서 알림을 탭하면 항상 selectedTodoID를 설정하여 화면 이동을 트리거하고, 해당 알림이 아직 읽지 않은 상태일 경우에만 읽음으로 처리하도록 수정하는 것을 제안합니다.

Suggested change
if let index = state.notifications.firstIndex(where: { $0.id == item.id }), !item.isRead {
state.selectedTodoID = TodoIDItem(id: item.todoID)
state.notifications[index].isRead.toggle()
return [.toggleRead(item.todoID)]
}
state.selectedTodoID = TodoIDItem(id: item.todoID)
if let index = state.notifications.firstIndex(where: { $0.id == item.id }) {
if !state.notifications[index].isRead {
state.notifications[index].isRead = true
return [.toggleRead(item.todoID)]
}
}

default:
break
}
Expand Down Expand Up @@ -252,7 +256,7 @@ private extension PushNotificationViewModel {
}
}

private extension PushNotificationViewModel {
private extension PushNotificationListViewModel {
func setAlert(
_ state: inout State,
isPresented: Bool,
Expand Down
2 changes: 1 addition & 1 deletion DevLog/UI/Common/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//
// PushNotificationView.swift
// PushNotificationListView.swift
// DevLog
//
// Created by opfic on 5/14/25.
//

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
Expand Down