diff --git a/Modules/Sources/FavoritesFeature/FavoritesFeature.swift b/Modules/Sources/FavoritesFeature/FavoritesFeature.swift index 87f89956..9c7daf37 100644 --- a/Modules/Sources/FavoritesFeature/FavoritesFeature.swift +++ b/Modules/Sources/FavoritesFeature/FavoritesFeature.swift @@ -21,6 +21,15 @@ public struct FavoritesFeature: Reducer, Sendable { public init() {} + // MARK: - Localizations + + public enum Localization { + static let linkCopied = LocalizedStringResource("Link copied", bundle: .module) + static let markAsReadSuccess = LocalizedStringResource("Marked as read", bundle: .module) + static let notifyTypeChanged = LocalizedStringResource("Notify type changed", bundle: .module) + static let sortFiltersChanged = LocalizedStringResource("Sort filters are changed", bundle: .module) + } + // MARK: - State @ObservableState @@ -112,10 +121,14 @@ public struct FavoritesFeature: Reducer, Sendable { return .send(.internal(.loadFavorites(offset: newOffset))) case .sort(.presented(.saveButtonTapped)): - return .run { send in - await send(.internal(.refresh)) - await send(.sort(.presented(.cancelButtonTapped))) - } + return .concatenate( + .run { _ in + await toastClient.showToast(ToastMessage(text: Localization.sortFiltersChanged, haptic: .success)) + }, + + .send(.internal(.refresh)), + .send(.sort(.presented(.cancelButtonTapped))) + ) case .sort(.presented(.cancelButtonTapped)): state.sort = nil @@ -179,9 +192,9 @@ public struct FavoritesFeature: Reducer, Sendable { case .markAllAsRead: return .run { send in - _ = try await apiClient.readAllFavorites() - // TODO: Display toast on success/error. - + let status = try await apiClient.readAllFavorites() + let success = ToastMessage(text: Localization.markAsReadSuccess, haptic: .success) + await toastClient.showToast(status ? success : .whoopsSomethingWentWrong) await send(.internal(.refresh)) } } @@ -191,29 +204,30 @@ public struct FavoritesFeature: Reducer, Sendable { case .copyLink(let id): let show = isForum ? "showforum" : "showtopic" pasteboardClient.copy("https://4pda.to/forum/index.php?\(show)=\(id)") - return .none + return .run { _ in + await toastClient.showToast(ToastMessage(text: Localization.linkCopied, haptic: .success)) + } case .delete(let id): return .run { send in let request = SetFavoriteRequest(id: id, action: .delete, type: isForum ? .forum : .topic) - _ = try await apiClient.setFavorite(request) - // TODO: Display toast on success/error. - + let status = try await apiClient.setFavorite(request) + await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong) await send(.internal(.refresh)) } case .setImportant(let id, let pin): return .run { send in let request = SetFavoriteRequest(id: id, action: pin ? .pin : .unpin, type: isForum ? .forum : .topic) - _ = try await apiClient.setFavorite(request) - // TODO: Display toast on success/error. - + let status = try await apiClient.setFavorite(request) + await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong) await send(.internal(.refresh)) } case .markRead(let id): return .run { [id, isForum] send in - let _ = try await apiClient.markRead(id: id, isTopic: !isForum) + let status = try await apiClient.markRead(id: id, isTopic: !isForum) + await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong) await send(.internal(.refresh)) } } @@ -231,9 +245,9 @@ public struct FavoritesFeature: Reducer, Sendable { case .notify(let flag, let notify): return .run { send in let request = NotifyFavoriteRequest(id: favorite.topic.id, flag: flag, type: notify) - _ = try await apiClient.notifyFavorite(request) - // TODO: Display toast on success/error. - + let status = try await apiClient.notifyFavorite(request) + let notifyTypeChangedToast = ToastMessage(text: Localization.notifyTypeChanged, haptic: .success) + await toastClient.showToast(status ? notifyTypeChangedToast : .whoopsSomethingWentWrong) await send(.internal(.refresh)) } } diff --git a/Modules/Sources/FavoritesFeature/Resources/Localizable.xcstrings b/Modules/Sources/FavoritesFeature/Resources/Localizable.xcstrings index f3b76d87..bbdbb6ab 100644 --- a/Modules/Sources/FavoritesFeature/Resources/Localizable.xcstrings +++ b/Modules/Sources/FavoritesFeature/Resources/Localizable.xcstrings @@ -131,6 +131,16 @@ } } }, + "Link copied" : { + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Ссылка скопирована" + } + } + } + }, "Mark As Read" : { "localizations" : { "ru" : { @@ -141,6 +151,16 @@ } } }, + "Marked as read" : { + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Отмечено прочитанным" + } + } + } + }, "No favorites" : { "localizations" : { "ru" : { @@ -171,6 +191,16 @@ } } }, + "Notify type changed" : { + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Тип уведомлений изменен" + } + } + } + }, "Once" : { "localizations" : { "ru" : { @@ -211,6 +241,16 @@ } } }, + "Sort filters are changed" : { + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Фильтры сортировки обновлены" + } + } + } + }, "To Important" : { "localizations" : { "ru" : { diff --git a/Modules/Sources/ForumFeature/ForumFeature.swift b/Modules/Sources/ForumFeature/ForumFeature.swift index 560a6be3..9d8dc986 100644 --- a/Modules/Sources/ForumFeature/ForumFeature.swift +++ b/Modules/Sources/ForumFeature/ForumFeature.swift @@ -21,6 +21,13 @@ public struct ForumFeature: Reducer, Sendable { public init() {} + // MARK: - Localizations + + public enum Localization { + static let linkCopied = LocalizedStringResource("Link copied", bundle: .module) + static let markAsReadSuccess = LocalizedStringResource("Marked as read", bundle: .module) + } + // MARK: - Enums public struct SectionExpand: Equatable { @@ -197,7 +204,9 @@ public struct ForumFeature: Reducer, Sendable { case .copyLink: let show = isForum ? "showforum" : "showtopic" pasteboardClient.copy("https://4pda.to/forum/index.php?\(show)=\(id)") - return .none + return .run { _ in + await toastClient.showToast(ToastMessage(text: Localization.linkCopied, haptic: .success)) + } case .openInBrowser: let show = isForum ? "showforum" : "showtopic" @@ -206,7 +215,9 @@ public struct ForumFeature: Reducer, Sendable { case .markRead: return .run { [id, isForum] send in - let _ = try await apiClient.markRead(id: id, isTopic: !isForum) + let status = try await apiClient.markRead(id: id, isTopic: !isForum) + let markedAsRead = ToastMessage(text: Localization.markAsReadSuccess, haptic: .success) + await toastClient.showToast(status ? markedAsRead : .whoopsSomethingWentWrong) await send(.internal(.refresh)) } @@ -217,18 +228,10 @@ public struct ForumFeature: Reducer, Sendable { action: isFavorite ? .delete : .add, type: isForum ? .forum : .topic ) - let _ = try await apiClient.setFavorite(request) + let status = try await apiClient.setFavorite(request) notificationCenter.post(name: .favoritesUpdated, object: nil) await send(.internal(.refresh)) - // TODO: We don't know if it's added or removed from api - // let text: LocalizedStringResource - // if isAdded { - // text = LocalizedStringResource("Added to favorites", bundle: .module) - // } else { - // text = LocalizedStringResource("Removed from favorites", bundle: .module) - // } - // let toast = ToastMessage(text: text, haptic: .success) - // await toastClient.showToast(toast) + await toastClient.showToast(status ? .actionCompleted : .whoopsSomethingWentWrong) } catch: { _, _ in await toastClient.showToast(.whoopsSomethingWentWrong) } diff --git a/Modules/Sources/ForumFeature/Resources/Localizable.xcstrings b/Modules/Sources/ForumFeature/Resources/Localizable.xcstrings index 864386cb..9a7616b0 100644 --- a/Modules/Sources/ForumFeature/Resources/Localizable.xcstrings +++ b/Modules/Sources/ForumFeature/Resources/Localizable.xcstrings @@ -41,6 +41,16 @@ } } }, + "Link copied" : { + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Ссылка скопирована" + } + } + } + }, "Mark Read" : { "localizations" : { "ru" : { @@ -51,6 +61,16 @@ } } }, + "Marked as read" : { + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Отмечено прочитанным" + } + } + } + }, "Open" : { "localizations" : { "ru" : { diff --git a/Modules/Sources/GalleryFeature/TabViewGallery.swift b/Modules/Sources/GalleryFeature/TabViewGallery.swift index 9fb48c84..3a166e52 100644 --- a/Modules/Sources/GalleryFeature/TabViewGallery.swift +++ b/Modules/Sources/GalleryFeature/TabViewGallery.swift @@ -74,6 +74,8 @@ public struct TabViewGallery: View { } .ignoresSafeArea() } + .statusBarHidden(!isTouched) + .animation(.easeInOut, value: !isTouched) .onAppear { deleteTempFiles() preloadImage() diff --git a/Modules/Sources/ToastClient/Models/ToastMessage.swift b/Modules/Sources/ToastClient/Models/ToastMessage.swift index 399f0b73..59d592a9 100644 --- a/Modules/Sources/ToastClient/Models/ToastMessage.swift +++ b/Modules/Sources/ToastClient/Models/ToastMessage.swift @@ -42,6 +42,14 @@ public struct ToastMessage: Equatable, Sendable { } public extension ToastMessage { + static let actionCompleted = ToastMessage( + text: LocalizedStringResource("Action completed", bundle: .module), + isError: false, + haptic: .success, + duration: 3, + priority: .low + ) + static let whoopsSomethingWentWrong = ToastMessage( text: LocalizedStringResource("Whoops, something went wrong..", bundle: .module), isError: true, diff --git a/Modules/Sources/ToastClient/Resources/Localizable.xcstrings b/Modules/Sources/ToastClient/Resources/Localizable.xcstrings index abc296f5..592cff6a 100644 --- a/Modules/Sources/ToastClient/Resources/Localizable.xcstrings +++ b/Modules/Sources/ToastClient/Resources/Localizable.xcstrings @@ -1,6 +1,16 @@ { "sourceLanguage" : "en", "strings" : { + "Action completed" : { + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Действие выполнено" + } + } + } + }, "Whoops, something went wrong.." : { "localizations" : { "ru" : { diff --git a/Modules/Sources/TopicFeature/TopicFeature.swift b/Modules/Sources/TopicFeature/TopicFeature.swift index bade73c4..46795045 100644 --- a/Modules/Sources/TopicFeature/TopicFeature.swift +++ b/Modules/Sources/TopicFeature/TopicFeature.swift @@ -30,6 +30,7 @@ public struct TopicFeature: Reducer, Sendable { // MARK: - Localizations private enum Localization { + static let linkCopied = LocalizedStringResource("Link copied", bundle: .module) static let favoriteAdded = LocalizedStringResource("Added to favorites", bundle: .module) static let favoriteRemoved = LocalizedStringResource("Removed from favorites", bundle: .module) static let postDeleted = LocalizedStringResource("Post deleted", bundle: .module) @@ -254,7 +255,9 @@ public struct TopicFeature: Reducer, Sendable { case .copyLink: pasteboardClient.copy("https://4pda.to/forum/index.php?showtopic=\(topic.id)") - return .none + return .run { _ in + await toastClient.showToast(ToastMessage(text: Localization.linkCopied, haptic: .success)) + } case .setFavorite: return .run { [id = state.topicId] send in @@ -336,8 +339,7 @@ public struct TopicFeature: Reducer, Sendable { let link = "https://4pda.to/forum/index.php?showtopic=\(state.topicId)&view=findpost&p=\(postId)" pasteboardClient.copy(link) return .run { _ in - let toast = ToastMessage(text: LocalizedStringResource("Link copied", bundle: .module), haptic: .success) - await toastClient.showToast(toast) + await toastClient.showToast(ToastMessage(text: Localization.linkCopied, haptic: .success)) } } diff --git a/Modules/Sources/WriteFormFeature/Preview/FormPreviewView.swift b/Modules/Sources/WriteFormFeature/Preview/FormPreviewView.swift index d1e3f674..86454f88 100644 --- a/Modules/Sources/WriteFormFeature/Preview/FormPreviewView.swift +++ b/Modules/Sources/WriteFormFeature/Preview/FormPreviewView.swift @@ -32,7 +32,7 @@ struct FormPreviewView: View { // links will be opening in browser. } } - } else { + } else if !store.isPreviewLoading { Text("Oops, error with loading preview :(", bundle: .module) .font(.headline) .foregroundStyle(tintColor)