Skip to content

Commit abe96d8

Browse files
authored
[#136] PushNotificationListView에서 row를 탭하면 푸시알람 데이터가 읽은 상태로 되도록 구현한다 (#140)
* style: PushNotification + ListView * feat: 탭했을 시 읽은 상태로 변경 * fix: 이미 읽은 알림인 경우 상세화면이 안뜨는 문제 해결
1 parent 0a9194c commit abe96d8

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

DevLog/Presentation/ViewModel/PushNotificationViewModel.swift renamed to DevLog/Presentation/ViewModel/PushNotificationListViewModel.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//
2-
// PushNotificationViewModel.swift
2+
// PushNotificationListViewModel.swift
33
// DevLog
44
//
55
// Created by 최윤진 on 11/22/25.
66
//
77

88
import Foundation
99

10-
final class PushNotificationViewModel: Store {
10+
final class PushNotificationListViewModel: Store {
1111
struct State {
1212
var notifications: [PushNotification] = []
1313
var showAlert: Bool = false
@@ -157,7 +157,7 @@ final class PushNotificationViewModel: Store {
157157
}
158158

159159
// MARK: - Reduce Methods
160-
private extension PushNotificationViewModel {
160+
private extension PushNotificationListViewModel {
161161
func reduceByUser(_ action: Action, state: inout State) -> [SideEffect] {
162162
switch action {
163163
case .deleteNotification(let item):
@@ -197,8 +197,12 @@ private extension PushNotificationViewModel {
197197
updateQueryUseCase.execute(state.query)
198198
state.nextCursor = nil
199199
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+
}
202206
default:
203207
break
204208
}
@@ -252,7 +256,7 @@ private extension PushNotificationViewModel {
252256
}
253257
}
254258

255-
private extension PushNotificationViewModel {
259+
private extension PushNotificationListViewModel {
256260
func setAlert(
257261
_ state: inout State,
258262
isPresented: Bool,

DevLog/UI/Common/MainView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct MainView: View {
2323
Image(systemName: "house.fill")
2424
Text("")
2525
}
26-
PushNotificationView(viewModel: PushNotificationViewModel(
26+
PushNotificationListView(viewModel: PushNotificationListViewModel(
2727
fetchUseCase: container.resolve(FetchPushNotificationsUseCase.self),
2828
deleteUseCase: container.resolve(DeletePushNotificationUseCase.self),
2929
toggleReadUseCase: container.resolve(TogglePushNotificationReadUseCase.self),

DevLog/UI/PushNotification/PushNotificationView.swift renamed to DevLog/UI/PushNotification/PushNotificationListView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//
2-
// PushNotificationView.swift
2+
// PushNotificationListView.swift
33
// DevLog
44
//
55
// Created by opfic on 5/14/25.
66
//
77

88
import SwiftUI
99

10-
struct PushNotificationView: View {
10+
struct PushNotificationListView: View {
1111
@StateObject private var router = NavigationRouter()
12-
@StateObject var viewModel: PushNotificationViewModel
12+
@StateObject var viewModel: PushNotificationListViewModel
1313
@Environment(\.sceneWidth) private var sceneWidth
1414
@Environment(\.colorScheme) private var colorScheme
1515
@Environment(\.diContainer) private var container: DIContainer

0 commit comments

Comments
 (0)