Skip to content

Commit d182628

Browse files
committed
Favorites toasts improvements
1 parent eb3a55d commit d182628

File tree

1 file changed

+30
-45
lines changed

1 file changed

+30
-45
lines changed

Modules/Sources/FavoritesFeature/FavoritesFeature.swift

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,12 @@ public struct FavoritesFeature: Reducer, Sendable {
191191
return .none
192192

193193
case .markAllAsRead:
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-
},
200-
201-
.send(.internal(.refresh))
202-
)
194+
return .run { send in
195+
let status = try await apiClient.readAllFavorites()
196+
let success = ToastMessage(text: Localization.markAsReadSuccess, haptic: .success)
197+
await toastClient.showToast(status ? success : .whoopsSomethingWentWrong)
198+
await send(.internal(.refresh))
199+
}
203200
}
204201

205202
case .view(.commonContextMenu(let action, let isForum)):
@@ -212,36 +209,27 @@ public struct FavoritesFeature: Reducer, Sendable {
212209
}
213210

214211
case .delete(let id):
215-
return .concatenate(
216-
.run { send in
217-
let request = SetFavoriteRequest(id: id, action: .delete, type: isForum ? .forum : .topic)
218-
let status = try await apiClient.setFavorite(request)
219-
await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong)
220-
},
221-
222-
.send(.internal(.refresh))
223-
)
212+
return .run { send in
213+
let request = SetFavoriteRequest(id: id, action: .delete, type: isForum ? .forum : .topic)
214+
let status = try await apiClient.setFavorite(request)
215+
await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong)
216+
await send(.internal(.refresh))
217+
}
224218

225219
case .setImportant(let id, let pin):
226-
return .concatenate(
227-
.run { send in
228-
let request = SetFavoriteRequest(id: id, action: pin ? .pin : .unpin, type: isForum ? .forum : .topic)
229-
let status = try await apiClient.setFavorite(request)
230-
await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong)
231-
},
232-
233-
.send(.internal(.refresh))
234-
)
220+
return .run { send in
221+
let request = SetFavoriteRequest(id: id, action: pin ? .pin : .unpin, type: isForum ? .forum : .topic)
222+
let status = try await apiClient.setFavorite(request)
223+
await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong)
224+
await send(.internal(.refresh))
225+
}
235226

236227
case .markRead(let id):
237-
return .concatenate(
238-
.run { [id, isForum] send in
239-
let status = try await apiClient.markRead(id: id, isTopic: !isForum)
240-
await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong)
241-
},
242-
243-
.send(.internal(.refresh))
244-
)
228+
return .run { [id, isForum] send in
229+
let status = try await apiClient.markRead(id: id, isTopic: !isForum)
230+
await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong)
231+
await send(.internal(.refresh))
232+
}
245233
}
246234

247235
case let .view(.topicContextMenu(action, favorite)):
@@ -255,16 +243,13 @@ public struct FavoritesFeature: Reducer, Sendable {
255243
}
256244

257245
case .notify(let flag, let notify):
258-
return .concatenate(
259-
.run { send in
260-
let request = NotifyFavoriteRequest(id: favorite.topic.id, flag: flag, type: notify)
261-
let status = try await apiClient.notifyFavorite(request)
262-
let notifyTypeChangedToast = ToastMessage(text: Localization.notifyTypeChanged, haptic: .success)
263-
await toastClient.showToast(status ? notifyTypeChangedToast : .whoopsSomethingWentWrong)
264-
},
265-
266-
.send(.internal(.refresh))
267-
)
246+
return .run { send in
247+
let request = NotifyFavoriteRequest(id: favorite.topic.id, flag: flag, type: notify)
248+
let status = try await apiClient.notifyFavorite(request)
249+
let notifyTypeChangedToast = ToastMessage(text: Localization.notifyTypeChanged, haptic: .success)
250+
await toastClient.showToast(status ? notifyTypeChangedToast : .whoopsSomethingWentWrong)
251+
await send(.internal(.refresh))
252+
}
268253
}
269254

270255
case .internal(.refresh):

0 commit comments

Comments
 (0)