diff --git a/apple/OmnivoreKit/Sources/App/SnackbarExtension.swift b/apple/OmnivoreKit/Sources/App/SnackbarExtension.swift new file mode 100644 index 000000000..fab837616 --- /dev/null +++ b/apple/OmnivoreKit/Sources/App/SnackbarExtension.swift @@ -0,0 +1,9 @@ +import Foundation +import Services +import Views + +extension Snackbar { + static func show(message: String) { + NSNotification.operationSuccess(message: message) + } +} diff --git a/apple/OmnivoreKit/Sources/App/Views/HomeFeedView.swift b/apple/OmnivoreKit/Sources/App/Views/HomeFeedView.swift index 7f5d2fc46..13cb2ca1d 100644 --- a/apple/OmnivoreKit/Sources/App/Views/HomeFeedView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/HomeFeedView.swift @@ -113,7 +113,7 @@ final class HomeFeedViewModel: ObservableObject { receiveValue: { [weak self] _ in self?.isLoading = false stopNetworkActivityIndicator() - NSNotification.operationSuccess(message: archived ? "Link archived" : "Link moved to Inbox") + Snackbar.show(message: archived ? "Link archived" : "Link moved to Inbox") } ) .store(in: &subscriptions) @@ -130,16 +130,15 @@ final class HomeFeedViewModel: ObservableObject { dataService.removeLinkPublisher(itemID: linkId) .sink( receiveCompletion: { [weak self] completion in - guard case let .failure(error) = completion else { return } + guard case .failure = completion else { return } self?.isLoading = false stopNetworkActivityIndicator() - print(error) - NSNotification.operationFailed(message: "Failed to remove link") + Snackbar.show(message: "Failed to remove link") }, receiveValue: { [weak self] _ in self?.isLoading = false stopNetworkActivityIndicator() - NSNotification.operationSuccess(message: "Link removed") + Snackbar.show(message: "Link removed") } ) .store(in: &subscriptions) @@ -169,7 +168,7 @@ final class HomeFeedViewModel: ObservableObject { self?.isLoading = false stopNetworkActivityIndicator() if let message = successMessage { - NSNotification.operationSuccess(message: message) + Snackbar.show(message: message) } } ) diff --git a/apple/OmnivoreKit/Sources/App/Views/Profile/NewsletterEmailsView.swift b/apple/OmnivoreKit/Sources/App/Views/Profile/NewsletterEmailsView.swift index 1eaf65a44..0e7063d36 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Profile/NewsletterEmailsView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Profile/NewsletterEmailsView.swift @@ -2,6 +2,7 @@ import Combine import Models import Services import SwiftUI +import Views final class NewsletterEmailsViewModel: ObservableObject { private var hasLoadedInitialEmails = false @@ -94,7 +95,7 @@ struct NewsletterEmailsView: View { pasteBoard.writeObjects([newsletterEmail.email as NSString]) #endif - NSNotification.operationSuccess(message: "Email copied") + Snackbar.show(message: "Email copied") }, label: { Text(newsletterEmail.email) } ) diff --git a/apple/OmnivoreKit/Sources/Views/SnackBar.swift b/apple/OmnivoreKit/Sources/Views/SnackBar.swift index aed304e18..89b8b86f5 100644 --- a/apple/OmnivoreKit/Sources/Views/SnackBar.swift +++ b/apple/OmnivoreKit/Sources/Views/SnackBar.swift @@ -1,6 +1,6 @@ import SwiftUI -struct Snackbar: View { +public struct Snackbar: View { @Binding var isShowing: Bool private let presenting: AnyView private let text: Text @@ -27,7 +27,7 @@ struct Snackbar: View { self.action = action } - var body: some View { + public var body: some View { GeometryReader { geometry in ZStack(alignment: .center) { self.presenting