@@ -13,10 +13,8 @@ final class PushNotificationListViewModel: Store {
1313 var showAlert : Bool = false
1414 var showToast : Bool = false
1515 var alertTitle : String = " "
16- var alertType : AlertType ?
1716 var alertMessage : String = " "
1817 var toastMessage : String = " "
19- var toastType : ToastType ?
2018 var isLoading : Bool = false
2119 var hasMore : Bool = false
2220 var nextCursor : PushNotificationCursor ?
@@ -32,8 +30,8 @@ final class PushNotificationListViewModel: Store {
3230 case toggleRead( PushNotification )
3331 case undoDelete
3432 case confirmDelete
35- case setAlert( isPresented: Bool , type : AlertType ? = nil )
36- case setToast( isPresented: Bool , type : ToastType ? = nil )
33+ case setAlert( isPresented: Bool )
34+ case setToast( isPresented: Bool )
3735 case setLoading( Bool )
3836 case appendNotifications( [ PushNotification ] , nextCursor: PushNotificationCursor ? )
3937 case resetPagination
@@ -52,14 +50,6 @@ final class PushNotificationListViewModel: Store {
5250 case toggleRead( String )
5351 }
5452
55- enum AlertType {
56- case error
57- }
58-
59- enum ToastType {
60- case delete
61- }
62-
6353 @Published private( set) var state : State
6454 private let fetchUseCase : FetchPushNotificationsUseCase
6555 private let deleteUseCase : DeletePushNotificationUseCase
@@ -128,7 +118,7 @@ final class PushNotificationListViewModel: Store {
128118 let hasMore = page. items. count == query. pageSize && page. nextCursor != nil
129119 send ( . setHasMore( hasMore) )
130120 } catch {
131- send ( . setAlert( isPresented: true , type : . error ) )
121+ send ( . setAlert( isPresented: true ) )
132122 }
133123
134124 }
@@ -139,7 +129,7 @@ final class PushNotificationListViewModel: Store {
139129 send ( . setLoading( true ) )
140130 try await deleteUseCase. execute ( notification. id)
141131 } catch {
142- send ( . setAlert( isPresented: true , type : . error ) )
132+ send ( . setAlert( isPresented: true ) )
143133 }
144134 }
145135 case . toggleRead( let todoID) :
@@ -149,7 +139,7 @@ final class PushNotificationListViewModel: Store {
149139 send ( . setLoading( true ) )
150140 try await toggleReadUseCase. execute ( todoID)
151141 } catch {
152- send ( . setAlert( isPresented: true , type : . error ) )
142+ send ( . setAlert( isPresented: true ) )
153143 }
154144 }
155145 }
@@ -169,7 +159,7 @@ private extension PushNotificationListViewModel {
169159 if let index = state. notifications. firstIndex ( where: { $0. id == item. id } ) {
170160 state. pendingTask = ( item, index)
171161 state. notifications. remove ( at: index)
172- setToast ( & state, isPresented: true , for : . delete )
162+ setToast ( & state, isPresented: true )
173163 }
174164
175165 return effects
@@ -182,8 +172,8 @@ private extension PushNotificationListViewModel {
182172 guard let ( item, index) = state. pendingTask else { return [ ] }
183173 state. notifications. insert ( item, at: index)
184174 state. pendingTask = nil
185- case . setAlert( let isPresented, let type ) :
186- setAlert ( & state, isPresented: isPresented, for : type )
175+ case . setAlert( let isPresented) :
176+ setAlert ( & state, isPresented: isPresented)
187177 case . toggleSortOption:
188178 state. query. sortOrder = state. query. sortOrder == . latest ? . oldest : . latest
189179 updateQueryUseCase. execute ( state. query)
@@ -228,8 +218,8 @@ private extension PushNotificationListViewModel {
228218 guard let ( item, _) = state. pendingTask else { return [ ] }
229219 state. pendingTask = nil
230220 return [ . delete( item) ]
231- case . setToast( let isPresented, let type ) :
232- setToast ( & state, isPresented: isPresented, for : type )
221+ case . setToast( let isPresented) :
222+ setToast ( & state, isPresented: isPresented)
233223 case . setSelectedTodoID( let todoID) :
234224 state. selectedTodoID = todoID
235225 default :
@@ -266,32 +256,18 @@ private extension PushNotificationListViewModel {
266256private extension PushNotificationListViewModel {
267257 func setAlert(
268258 _ state: inout State ,
269- isPresented: Bool ,
270- for type: AlertType ?
259+ isPresented: Bool
271260 ) {
272- switch type {
273- case . error:
274- state. alertTitle = " 오류 "
275- state. alertMessage = " 문제가 발생했습니다. 잠시 후 다시 시도해주세요. "
276- case . none:
277- state. alertTitle = " "
278- state. alertMessage = " "
279- }
280- state. alertType = type
261+ state. alertTitle = " 오류 "
262+ state. alertMessage = " 문제가 발생했습니다. 잠시 후 다시 시도해주세요. "
281263 state. showAlert = isPresented
282264 }
283265
284266 func setToast(
285267 _ state: inout State ,
286- isPresented: Bool ,
287- for type: ToastType ?
268+ isPresented: Bool
288269 ) {
289- switch type {
290- case . delete:
291- state. toastMessage = " 실행 취소 "
292- case . none:
293- state. toastMessage = " "
294- }
270+ state. toastMessage = " 실행 취소 "
295271 state. showToast = isPresented
296272 }
297273}
0 commit comments