-
Notifications
You must be signed in to change notification settings - Fork 0
[#141] PushNotificationListView에서 여러 데이터를 제거 후 다른 뷰로 넘어갔다 돌아오면 지워졌던 데이터가 롤백되는 현상을 해결한다 #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,10 +13,8 @@ final class PushNotificationListViewModel: Store { | |
| var showAlert: Bool = false | ||
| var showToast: Bool = false | ||
| var alertTitle: String = "" | ||
| var alertType: AlertType? | ||
| var alertMessage: String = "" | ||
| var toastMessage: String = "" | ||
| var toastType: ToastType? | ||
| var isLoading: Bool = false | ||
| var hasMore: Bool = false | ||
| var nextCursor: PushNotificationCursor? | ||
|
|
@@ -32,8 +30,8 @@ final class PushNotificationListViewModel: Store { | |
| case toggleRead(PushNotification) | ||
| case undoDelete | ||
| case confirmDelete | ||
| case setAlert(isPresented: Bool, type: AlertType? = nil) | ||
| case setToast(isPresented: Bool, type: ToastType? = nil) | ||
| case setAlert(isPresented: Bool) | ||
| case setToast(isPresented: Bool) | ||
| case setLoading(Bool) | ||
| case appendNotifications([PushNotification], nextCursor: PushNotificationCursor?) | ||
| case resetPagination | ||
|
|
@@ -52,14 +50,6 @@ final class PushNotificationListViewModel: Store { | |
| case toggleRead(String) | ||
| } | ||
|
|
||
| enum AlertType { | ||
| case error | ||
| } | ||
|
|
||
| enum ToastType { | ||
| case delete | ||
| } | ||
|
|
||
| @Published private(set) var state: State | ||
| private let fetchUseCase: FetchPushNotificationsUseCase | ||
| private let deleteUseCase: DeletePushNotificationUseCase | ||
|
|
@@ -128,7 +118,7 @@ final class PushNotificationListViewModel: Store { | |
| let hasMore = page.items.count == query.pageSize && page.nextCursor != nil | ||
| send(.setHasMore(hasMore)) | ||
| } catch { | ||
| send(.setAlert(isPresented: true, type: .error)) | ||
| send(.setAlert(isPresented: true)) | ||
| } | ||
|
|
||
| } | ||
|
|
@@ -139,7 +129,7 @@ final class PushNotificationListViewModel: Store { | |
| send(.setLoading(true)) | ||
| try await deleteUseCase.execute(notification.id) | ||
| } catch { | ||
| send(.setAlert(isPresented: true, type: .error)) | ||
| send(.setAlert(isPresented: true)) | ||
| } | ||
| } | ||
| case .toggleRead(let todoID): | ||
|
|
@@ -149,7 +139,7 @@ final class PushNotificationListViewModel: Store { | |
| send(.setLoading(true)) | ||
| try await toggleReadUseCase.execute(todoID) | ||
| } catch { | ||
| send(.setAlert(isPresented: true, type: .error)) | ||
| send(.setAlert(isPresented: true)) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -161,11 +151,18 @@ private extension PushNotificationListViewModel { | |
| func reduceByUser(_ action: Action, state: inout State) -> [SideEffect] { | ||
| switch action { | ||
| case .deleteNotification(let item): | ||
| var effects: [SideEffect] = [] | ||
| if let (pendingItem, _) = state.pendingTask { | ||
| effects = [.delete(pendingItem)] | ||
| } | ||
|
|
||
| if let index = state.notifications.firstIndex(where: { $0.id == item.id }) { | ||
| state.pendingTask = (item, index) | ||
| state.notifications.remove(at: index) | ||
| setToast(&state, isPresented: true, for: .delete) | ||
| setToast(&state, isPresented: true) | ||
| } | ||
|
|
||
| return effects | ||
| case .toggleRead(let item): | ||
| if let index = state.notifications.firstIndex(where: { $0.id == item.id }) { | ||
| state.notifications[index].isRead.toggle() | ||
|
|
@@ -175,8 +172,8 @@ private extension PushNotificationListViewModel { | |
| guard let (item, index) = state.pendingTask else { return [] } | ||
| state.notifications.insert(item, at: index) | ||
| state.pendingTask = nil | ||
| case .setAlert(let isPresented, let type): | ||
| setAlert(&state, isPresented: isPresented, for: type) | ||
| case .setAlert(let isPresented): | ||
| setAlert(&state, isPresented: isPresented) | ||
| case .toggleSortOption: | ||
| state.query.sortOrder = state.query.sortOrder == .latest ? .oldest : .latest | ||
| updateQueryUseCase.execute(state.query) | ||
|
|
@@ -221,8 +218,8 @@ private extension PushNotificationListViewModel { | |
| guard let (item, _) = state.pendingTask else { return [] } | ||
| state.pendingTask = nil | ||
| return [.delete(item)] | ||
| case .setToast(let isPresented, let type): | ||
| setToast(&state, isPresented: isPresented, for: type) | ||
| case .setToast(let isPresented): | ||
| setToast(&state, isPresented: isPresented) | ||
| case .setSelectedTodoID(let todoID): | ||
| state.selectedTodoID = todoID | ||
| default: | ||
|
|
@@ -259,32 +256,18 @@ private extension PushNotificationListViewModel { | |
| private extension PushNotificationListViewModel { | ||
| func setAlert( | ||
| _ state: inout State, | ||
| isPresented: Bool, | ||
| for type: AlertType? | ||
| isPresented: Bool | ||
| ) { | ||
| switch type { | ||
| case .error: | ||
| state.alertTitle = "오류" | ||
| state.alertMessage = "문제가 발생했습니다. 잠시 후 다시 시도해주세요." | ||
| case .none: | ||
| state.alertTitle = "" | ||
| state.alertMessage = "" | ||
| } | ||
| state.alertType = type | ||
| state.alertTitle = "오류" | ||
| state.alertMessage = "문제가 발생했습니다. 잠시 후 다시 시도해주세요." | ||
| state.showAlert = isPresented | ||
| } | ||
|
Comment on lines
257
to
264
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
func setAlert(
_ state: inout State,
isPresented: Bool
) {
if isPresented {
state.alertTitle = "오류"
state.alertMessage = "문제가 발생했습니다. 잠시 후 다시 시도해주세요."
} else {
state.alertTitle = ""
state.alertMessage = ""
}
state.showAlert = isPresented
} |
||
|
|
||
| func setToast( | ||
| _ state: inout State, | ||
| isPresented: Bool, | ||
| for type: ToastType? | ||
| isPresented: Bool | ||
| ) { | ||
| switch type { | ||
| case .delete: | ||
| state.toastMessage = "실행 취소" | ||
| case .none: | ||
| state.toastMessage = "" | ||
| } | ||
| state.toastMessage = "실행 취소" | ||
| state.showToast = isPresented | ||
|
Comment on lines
+270
to
271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
Comment on lines
266
to
272
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
func setToast(
_ state: inout State,
isPresented: Bool
) {
state.toastMessage = isPresented ? "실행 취소" : ""
state.showToast = isPresented
} |
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alert가 사라질 때 관련 상태(alertTitle, alertMessage)를 초기화하는 로직이 누락되었습니다. Alert가 다시 표시될 때 이전 메시지가 잠시 보이는 문제를 방지하기 위해
isPresented가false일 때 메시지를 비워주는 것이 좋습니다.