Skip to content

Commit 1b04157

Browse files
committed
Add toasts to forum
1 parent 5ca0795 commit 1b04157

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

Modules/Sources/ForumFeature/ForumFeature.swift

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Modules/Sources/ForumFeature/Resources/Localizable.xcstrings

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
}
4242
}
4343
},
44+
"Link copied" : {
45+
"localizations" : {
46+
"ru" : {
47+
"stringUnit" : {
48+
"state" : "translated",
49+
"value" : "Ссылка скопирована"
50+
}
51+
}
52+
}
53+
},
4454
"Mark Read" : {
4555
"localizations" : {
4656
"ru" : {
@@ -51,6 +61,16 @@
5161
}
5262
}
5363
},
64+
"Marked as read" : {
65+
"localizations" : {
66+
"ru" : {
67+
"stringUnit" : {
68+
"state" : "translated",
69+
"value" : "Отмечено прочитанным"
70+
}
71+
}
72+
}
73+
},
5474
"Open" : {
5575
"localizations" : {
5676
"ru" : {

0 commit comments

Comments
 (0)