Skip to content

Commit 79cebb4

Browse files
authored
Merge pull request #52 from SubvertDev/fixes/perfectionism
App experience improvements
2 parents 5bb6252 + 4c96e06 commit 79cebb4

File tree

9 files changed

+133
-34
lines changed

9 files changed

+133
-34
lines changed

Modules/Sources/FavoritesFeature/FavoritesFeature.swift

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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 linkCopied = LocalizedStringResource("Link copied", 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
@@ -179,9 +192,9 @@ public struct FavoritesFeature: Reducer, Sendable {
179192

180193
case .markAllAsRead:
181194
return .run { send in
182-
_ = try await apiClient.readAllFavorites()
183-
// TODO: Display toast on success/error.
184-
195+
let status = try await apiClient.readAllFavorites()
196+
let success = ToastMessage(text: Localization.markAsReadSuccess, haptic: .success)
197+
await toastClient.showToast(status ? success : .whoopsSomethingWentWrong)
185198
await send(.internal(.refresh))
186199
}
187200
}
@@ -191,29 +204,30 @@ public struct FavoritesFeature: Reducer, Sendable {
191204
case .copyLink(let id):
192205
let show = isForum ? "showforum" : "showtopic"
193206
pasteboardClient.copy("https://4pda.to/forum/index.php?\(show)=\(id)")
194-
return .none
207+
return .run { _ in
208+
await toastClient.showToast(ToastMessage(text: Localization.linkCopied, haptic: .success))
209+
}
195210

196211
case .delete(let id):
197212
return .run { send in
198213
let request = SetFavoriteRequest(id: id, action: .delete, type: isForum ? .forum : .topic)
199-
_ = try await apiClient.setFavorite(request)
200-
// TODO: Display toast on success/error.
201-
214+
let status = try await apiClient.setFavorite(request)
215+
await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong)
202216
await send(.internal(.refresh))
203217
}
204218

205219
case .setImportant(let id, let pin):
206220
return .run { send in
207221
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.
210-
222+
let status = try await apiClient.setFavorite(request)
223+
await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong)
211224
await send(.internal(.refresh))
212225
}
213226

214227
case .markRead(let id):
215228
return .run { [id, isForum] send in
216-
let _ = try await apiClient.markRead(id: id, isTopic: !isForum)
229+
let status = try await apiClient.markRead(id: id, isTopic: !isForum)
230+
await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong)
217231
await send(.internal(.refresh))
218232
}
219233
}
@@ -231,9 +245,9 @@ public struct FavoritesFeature: Reducer, Sendable {
231245
case .notify(let flag, let notify):
232246
return .run { send in
233247
let request = NotifyFavoriteRequest(id: favorite.topic.id, flag: flag, type: notify)
234-
_ = try await apiClient.notifyFavorite(request)
235-
// TODO: Display toast on success/error.
236-
248+
let status = try await apiClient.notifyFavorite(request)
249+
let notifyTypeChangedToast = ToastMessage(text: Localization.notifyTypeChanged, haptic: .success)
250+
await toastClient.showToast(status ? notifyTypeChangedToast : .whoopsSomethingWentWrong)
237251
await send(.internal(.refresh))
238252
}
239253
}

Modules/Sources/FavoritesFeature/Resources/Localizable.xcstrings

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@
131131
}
132132
}
133133
},
134+
"Link copied" : {
135+
"localizations" : {
136+
"ru" : {
137+
"stringUnit" : {
138+
"state" : "translated",
139+
"value" : "Ссылка скопирована"
140+
}
141+
}
142+
}
143+
},
134144
"Mark As Read" : {
135145
"localizations" : {
136146
"ru" : {
@@ -141,6 +151,16 @@
141151
}
142152
}
143153
},
154+
"Marked as read" : {
155+
"localizations" : {
156+
"ru" : {
157+
"stringUnit" : {
158+
"state" : "translated",
159+
"value" : "Отмечено прочитанным"
160+
}
161+
}
162+
}
163+
},
144164
"No favorites" : {
145165
"localizations" : {
146166
"ru" : {
@@ -171,6 +191,16 @@
171191
}
172192
}
173193
},
194+
"Notify type changed" : {
195+
"localizations" : {
196+
"ru" : {
197+
"stringUnit" : {
198+
"state" : "translated",
199+
"value" : "Тип уведомлений изменен"
200+
}
201+
}
202+
}
203+
},
174204
"Once" : {
175205
"localizations" : {
176206
"ru" : {
@@ -211,6 +241,16 @@
211241
}
212242
}
213243
},
244+
"Sort filters are changed" : {
245+
"localizations" : {
246+
"ru" : {
247+
"stringUnit" : {
248+
"state" : "translated",
249+
"value" : "Фильтры сортировки обновлены"
250+
}
251+
}
252+
}
253+
},
214254
"To Important" : {
215255
"localizations" : {
216256
"ru" : {

Modules/Sources/ForumFeature/ForumFeature.swift

Lines changed: 15 additions & 12 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,7 +204,9 @@ 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"
@@ -206,7 +215,9 @@ public struct ForumFeature: Reducer, Sendable {
206215

207216
case .markRead:
208217
return .run { [id, isForum] send in
209-
let _ = try await apiClient.markRead(id: id, isTopic: !isForum)
218+
let status = try await apiClient.markRead(id: id, isTopic: !isForum)
219+
let markedAsRead = ToastMessage(text: Localization.markAsReadSuccess, haptic: .success)
220+
await toastClient.showToast(status ? markedAsRead : .whoopsSomethingWentWrong)
210221
await send(.internal(.refresh))
211222
}
212223

@@ -217,18 +228,10 @@ public struct ForumFeature: Reducer, Sendable {
217228
action: isFavorite ? .delete : .add,
218229
type: isForum ? .forum : .topic
219230
)
220-
let _ = try await apiClient.setFavorite(request)
231+
let status = try await apiClient.setFavorite(request)
221232
notificationCenter.post(name: .favoritesUpdated, object: nil)
222233
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)
234+
await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong)
232235
} catch: { _, _ in
233236
await toastClient.showToast(.whoopsSomethingWentWrong)
234237
}

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" : {

Modules/Sources/GalleryFeature/TabViewGallery.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public struct TabViewGallery: View {
7474
}
7575
.ignoresSafeArea()
7676
}
77+
.statusBarHidden(!isTouched)
78+
.animation(.easeInOut, value: !isTouched)
7779
.onAppear {
7880
deleteTempFiles()
7981
preloadImage()

Modules/Sources/ToastClient/Models/ToastMessage.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public struct ToastMessage: Equatable, Sendable {
4242
}
4343

4444
public extension ToastMessage {
45+
static let actionCompleted = ToastMessage(
46+
text: LocalizedStringResource("Action completed", bundle: .module),
47+
isError: false,
48+
haptic: .success,
49+
duration: 3,
50+
priority: .low
51+
)
52+
4553
static let whoopsSomethingWentWrong = ToastMessage(
4654
text: LocalizedStringResource("Whoops, something went wrong..", bundle: .module),
4755
isError: true,

Modules/Sources/ToastClient/Resources/Localizable.xcstrings

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
{
22
"sourceLanguage" : "en",
33
"strings" : {
4+
"Action completed" : {
5+
"localizations" : {
6+
"ru" : {
7+
"stringUnit" : {
8+
"state" : "translated",
9+
"value" : "Действие выполнено"
10+
}
11+
}
12+
}
13+
},
414
"Whoops, something went wrong.." : {
515
"localizations" : {
616
"ru" : {

Modules/Sources/TopicFeature/TopicFeature.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public struct TopicFeature: Reducer, Sendable {
3030
// MARK: - Localizations
3131

3232
private enum Localization {
33+
static let linkCopied = LocalizedStringResource("Link copied", bundle: .module)
3334
static let favoriteAdded = LocalizedStringResource("Added to favorites", bundle: .module)
3435
static let favoriteRemoved = LocalizedStringResource("Removed from favorites", bundle: .module)
3536
static let postDeleted = LocalizedStringResource("Post deleted", bundle: .module)
@@ -269,7 +270,9 @@ public struct TopicFeature: Reducer, Sendable {
269270

270271
case .copyLink:
271272
pasteboardClient.copy("https://4pda.to/forum/index.php?showtopic=\(topic.id)")
272-
return .none
273+
return .run { _ in
274+
await toastClient.showToast(ToastMessage(text: Localization.linkCopied, haptic: .success))
275+
}
273276

274277
case .setFavorite:
275278
return .run { [id = state.topicId] send in
@@ -351,8 +354,7 @@ public struct TopicFeature: Reducer, Sendable {
351354
let link = "https://4pda.to/forum/index.php?showtopic=\(state.topicId)&view=findpost&p=\(postId)"
352355
pasteboardClient.copy(link)
353356
return .run { _ in
354-
let toast = ToastMessage(text: LocalizedStringResource("Link copied", bundle: .module), haptic: .success)
355-
await toastClient.showToast(toast)
357+
await toastClient.showToast(ToastMessage(text: Localization.linkCopied, haptic: .success))
356358
}
357359
}
358360

Modules/Sources/WriteFormFeature/Preview/FormPreviewView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct FormPreviewView: View {
3232
// links will be opening in browser.
3333
}
3434
}
35-
} else {
35+
} else if !store.isPreviewLoading {
3636
Text("Oops, error with loading preview :(", bundle: .module)
3737
.font(.headline)
3838
.foregroundStyle(tintColor)

0 commit comments

Comments
 (0)