@@ -21,6 +21,15 @@ public struct FavoritesFeature: Reducer, Sendable {
2121
2222 public init ( ) { }
2323
24+ // MARK: - Localizations
25+
26+ public enum Localization {
27+ static let actionCompleted = LocalizedStringResource ( " Action completed " , bundle: . module)
28+ static let markAsReadSuccess = LocalizedStringResource ( " Marked as read " , bundle: . module)
29+ static let notifyTypeChanged = LocalizedStringResource ( " Notify type changed " , bundle: . module)
30+ static let sortFiltersChanged = LocalizedStringResource ( " Sort filters are changed " , bundle: . module)
31+ }
32+
2433 // MARK: - State
2534
2635 @ObservableState
@@ -112,10 +121,14 @@ public struct FavoritesFeature: Reducer, Sendable {
112121 return . send( . internal( . loadFavorites( offset: newOffset) ) )
113122
114123 case . sort( . presented( . saveButtonTapped) ) :
115- return . run { send in
116- await send ( . internal( . refresh) )
117- await send ( . sort( . presented( . cancelButtonTapped) ) )
118- }
124+ return . concatenate(
125+ . run { _ in
126+ await toastClient. showToast ( ToastMessage ( text: Localization . sortFiltersChanged, haptic: . success) )
127+ } ,
128+
129+ . send( . internal( . refresh) ) ,
130+ . send( . sort( . presented( . cancelButtonTapped) ) )
131+ )
119132
120133 case . sort( . presented( . cancelButtonTapped) ) :
121134 state. sort = nil
@@ -178,12 +191,15 @@ public struct FavoritesFeature: Reducer, Sendable {
178191 return . none
179192
180193 case . markAllAsRead:
181- return . run { send in
182- _ = try await apiClient. readAllFavorites ( )
183- // TODO: Display toast on success/error.
194+ return . concatenate(
195+ . run { send in
196+ let status = try await apiClient. readAllFavorites ( )
197+ let success = ToastMessage ( text: Localization . markAsReadSuccess, haptic: . success)
198+ await toastClient. showToast ( status ? success : . whoopsSomethingWentWrong)
199+ } ,
184200
185- await send ( . internal( . refresh) )
186- }
201+ . send( . internal( . refresh) )
202+ )
187203 }
188204
189205 case . view( . commonContextMenu( let action, let isForum) ) :
@@ -194,28 +210,39 @@ public struct FavoritesFeature: Reducer, Sendable {
194210 return . none
195211
196212 case . delete( let id) :
197- return . run { send in
198- let request = SetFavoriteRequest ( id: id, action: . delete, type: isForum ? . forum : . topic)
199- _ = try await apiClient. setFavorite ( request)
200- // TODO: Display toast on success/error.
213+ return . concatenate(
214+ . run { send in
215+ let request = SetFavoriteRequest ( id: id, action: . delete, type: isForum ? . forum : . topic)
216+ let status = try await apiClient. setFavorite ( request)
217+ let actionCompleted = ToastMessage ( text: Localization . actionCompleted, haptic: . success)
218+ await toastClient. showToast ( status ? actionCompleted : . whoopsSomethingWentWrong)
219+ } ,
201220
202- await send ( . internal( . refresh) )
203- }
221+ . send( . internal( . refresh) )
222+ )
204223
205224 case . setImportant( let id, let pin) :
206- return . run { send in
207- let request = SetFavoriteRequest ( id: id, action: pin ? . pin : . unpin, type: isForum ? . forum : . topic)
208- _ = try await apiClient. setFavorite ( request)
209- // TODO: Display toast on success/error.
225+ return . concatenate(
226+ . run { send in
227+ let request = SetFavoriteRequest ( id: id, action: pin ? . pin : . unpin, type: isForum ? . forum : . topic)
228+ let status = try await apiClient. setFavorite ( request)
229+ let actionCompleted = ToastMessage ( text: Localization . actionCompleted, haptic: . success)
230+ await toastClient. showToast ( status ? actionCompleted : . whoopsSomethingWentWrong)
231+ } ,
210232
211- await send ( . internal( . refresh) )
212- }
233+ . send( . internal( . refresh) )
234+ )
213235
214236 case . markRead( let id) :
215- return . run { [ id, isForum] send in
216- let _ = try await apiClient. markRead ( id: id, isTopic: !isForum)
217- await send ( . internal( . refresh) )
218- }
237+ return . concatenate(
238+ . run { [ id, isForum] send in
239+ let status = try await apiClient. markRead ( id: id, isTopic: !isForum)
240+ let actionCompleted = ToastMessage ( text: Localization . actionCompleted, haptic: . success)
241+ await toastClient. showToast ( status ? actionCompleted : . whoopsSomethingWentWrong)
242+ } ,
243+
244+ . send( . internal( . refresh) )
245+ )
219246 }
220247
221248 case let . view( . topicContextMenu( action, favorite) ) :
@@ -229,13 +256,16 @@ public struct FavoritesFeature: Reducer, Sendable {
229256 }
230257
231258 case . notify( let flag, let notify) :
232- return . run { send in
233- let request = NotifyFavoriteRequest ( id: favorite. topic. id, flag: flag, type: notify)
234- _ = try await apiClient. notifyFavorite ( request)
235- // TODO: Display toast on success/error.
259+ return . concatenate(
260+ . run { send in
261+ let request = NotifyFavoriteRequest ( id: favorite. topic. id, flag: flag, type: notify)
262+ let status = try await apiClient. notifyFavorite ( request)
263+ let notifyTypeChangedToast = ToastMessage ( text: Localization . notifyTypeChanged, haptic: . success)
264+ await toastClient. showToast ( status ? notifyTypeChangedToast : . whoopsSomethingWentWrong)
265+ } ,
236266
237- await send ( . internal( . refresh) )
238- }
267+ . send( . internal( . refresh) )
268+ )
239269 }
240270
241271 case . internal( . refresh) :
0 commit comments