From c03c6e2a51cbf7683667a49dd1fd143b304e5bdc Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Mon, 5 Dec 2022 17:44:48 +0800 Subject: [PATCH] Use a share view for copying the group invite link --- .../Profile/RecommendationGroupView.swift | 25 +++++++++++-------- .../App/Views/WebReader/RecommendToView.swift | 8 ++++++ .../DataService/Mutations/RecommendPage.swift | 8 ++++++ 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 apple/OmnivoreKit/Sources/App/Views/WebReader/RecommendToView.swift create mode 100644 apple/OmnivoreKit/Sources/Services/DataService/Mutations/RecommendPage.swift diff --git a/apple/OmnivoreKit/Sources/App/Views/Profile/RecommendationGroupView.swift b/apple/OmnivoreKit/Sources/App/Views/Profile/RecommendationGroupView.swift index e4bdcba4e..21fe18470 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Profile/RecommendationGroupView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Profile/RecommendationGroupView.swift @@ -29,6 +29,8 @@ struct RecommendationGroupView: View { @EnvironmentObject var dataService: DataService @StateObject var viewModel: RecommendationsGroupViewModel + @State var presentShareSheet = false + var body: some View { Group { #if os(iOS) @@ -45,6 +47,14 @@ struct RecommendationGroupView: View { .task { await viewModel.loadGroups(dataService: dataService) } } + private var shareView: some View { + if let shareLink = URL(string: viewModel.recommendationGroup.inviteUrl) { + return AnyView(ShareSheet(activityItems: [shareLink])) + } else { + return AnyView(Text("Error copying invite URL")) + } + } + private var innerBody: some View { Group { Section("Name") { @@ -53,22 +63,15 @@ struct RecommendationGroupView: View { Section("Invite Link") { Button(action: { - #if os(iOS) - UIPasteboard.general.string = viewModel.recommendationGroup.inviteUrl - #endif - - #if os(macOS) - let pasteBoard = NSPasteboard.general - pasteBoard.clearContents() - pasteBoard.writeObjects([viewModel.recommendationGroup.inviteUrl as NSString]) - #endif - - Snackbar.show(message: "Invite link copied") + presentShareSheet = true }, label: { Text("[\(viewModel.recommendationGroup.inviteUrl)](\(viewModel.recommendationGroup.inviteUrl))") }) } } + .formSheet(isPresented: $presentShareSheet) { + shareView + } .navigationTitle(viewModel.recommendationGroup.name) } } diff --git a/apple/OmnivoreKit/Sources/App/Views/WebReader/RecommendToView.swift b/apple/OmnivoreKit/Sources/App/Views/WebReader/RecommendToView.swift new file mode 100644 index 000000000..aa2f9ef7e --- /dev/null +++ b/apple/OmnivoreKit/Sources/App/Views/WebReader/RecommendToView.swift @@ -0,0 +1,8 @@ +// +// File.swift +// +// +// Created by Jackson Harper on 12/5/22. +// + +import Foundation diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/RecommendPage.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/RecommendPage.swift new file mode 100644 index 000000000..aa2f9ef7e --- /dev/null +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/RecommendPage.swift @@ -0,0 +1,8 @@ +// +// File.swift +// +// +// Created by Jackson Harper on 12/5/22. +// + +import Foundation