@@ -21,6 +21,13 @@ public struct ForumFeature: Reducer, Sendable {
2121
2222 public init ( ) { }
2323
24+ // MARK: - Localizations
25+
26+ public enum Localization {
27+ static let linkCopied = LocalizedStringResource ( " Link copied " , bundle: . module)
28+ static let markAsReadSuccess = LocalizedStringResource ( " Marked as read " , bundle: . module)
29+ }
30+
2431 // MARK: - Enums
2532
2633 public struct SectionExpand : Equatable {
@@ -197,18 +204,25 @@ public struct ForumFeature: Reducer, Sendable {
197204 case . copyLink:
198205 let show = isForum ? " showforum " : " showtopic "
199206 pasteboardClient. copy ( " https://4pda.to/forum/index.php? \( show) = \( id) " )
200- return . none
207+ return . run { _ in
208+ await toastClient. showToast ( ToastMessage ( text: Localization . linkCopied, haptic: . success) )
209+ }
201210
202211 case . openInBrowser:
203212 let show = isForum ? " showforum " : " showtopic "
204213 let url = URL ( string: " https://4pda.to/forum/index.php? \( show) = \( id) " ) !
205214 return . run { _ in await open ( url: url) }
206215
207216 case . markRead:
208- return . run { [ id, isForum] send in
209- let _ = try await apiClient. markRead ( id: id, isTopic: !isForum)
210- await send ( . internal( . refresh) )
211- }
217+ return . concatenate(
218+ . run { [ id, isForum] send in
219+ let status = try await apiClient. markRead ( id: id, isTopic: !isForum)
220+ let markedAsRead = ToastMessage ( text: Localization . markAsReadSuccess, haptic: . success)
221+ await toastClient. showToast ( status ? markedAsRead : . whoopsSomethingWentWrong)
222+ } ,
223+
224+ . send( . internal( . refresh) )
225+ )
212226
213227 case . setFavorite( let isFavorite) :
214228 return . run { [ id = id, isFavorite = isFavorite, isForum = isForum] send in
@@ -217,18 +231,10 @@ public struct ForumFeature: Reducer, Sendable {
217231 action: isFavorite ? . delete : . add,
218232 type: isForum ? . forum : . topic
219233 )
220- let _ = try await apiClient. setFavorite ( request)
234+ let status = try await apiClient. setFavorite ( request)
221235 notificationCenter. post ( name: . favoritesUpdated, object: nil )
222236 await send ( . internal( . refresh) )
223- // TODO: We don't know if it's added or removed from api
224- // let text: LocalizedStringResource
225- // if isAdded {
226- // text = LocalizedStringResource("Added to favorites", bundle: .module)
227- // } else {
228- // text = LocalizedStringResource("Removed from favorites", bundle: .module)
229- // }
230- // let toast = ToastMessage(text: text, haptic: .success)
231- // await toastClient.showToast(toast)
237+ await toastClient. showToast ( status ? . actionCompleted : . whoopsSomethingWentWrong)
232238 } catch: { _, _ in
233239 await toastClient. showToast ( . whoopsSomethingWentWrong)
234240 }
0 commit comments