From b8bbfbb20877704d087f838de1360b416ab7a0ec Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Fri, 11 Dec 2020 14:44:20 -0500 Subject: [PATCH] Show sharing service picker on button press --- .../project.pbxproj | 2 +- macOS/Navigation/ActivePostToolbarView.swift | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj index c46754f..f94b76a 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj +++ b/WriteFreely-MultiPlatform.xcodeproj/project.pbxproj @@ -313,10 +313,10 @@ 17A67CAC251A5D8D002F163D /* PostEditor */ = { isa = PBXGroup; children = ( + 17479F142583D8E40072B7FB /* PostEditorSharingPicker.swift */, 17A67CAE251A5DD7002F163D /* PostEditorView.swift */, 17E5DF892543610700DCDC9B /* PostTextEditingView.swift */, 17466625256C0D0600629997 /* MacEditorTextView.swift */, - 17479F142583D8E40072B7FB /* PostEditorSharingPicker.swift */, ); path = PostEditor; sourceTree = ""; diff --git a/macOS/Navigation/ActivePostToolbarView.swift b/macOS/Navigation/ActivePostToolbarView.swift index 68b9d93..b7df978 100644 --- a/macOS/Navigation/ActivePostToolbarView.swift +++ b/macOS/Navigation/ActivePostToolbarView.swift @@ -3,19 +3,38 @@ import SwiftUI struct ActivePostToolbarView: View { @EnvironmentObject var model: WriteFreelyModel @ObservedObject var activePost: WFAPost + @State private var isPresentingSharingServicePicker: Bool = false var body: some View { HStack(spacing: 16) { PostEditorStatusToolbarView(post: activePost) HStack(spacing: 4) { - Button(action: {}, label: { Image(systemName: "square.and.arrow.up") }) - .disabled(activePost.status == PostStatus.local.rawValue) + Button( + action: { self.isPresentingSharingServicePicker = true }, + label: { Image(systemName: "square.and.arrow.up") } + ) + .disabled(activePost.status == PostStatus.local.rawValue) + .popover(isPresented: $isPresentingSharingServicePicker) { + PostEditorSharingPicker( + isPresented: $isPresentingSharingServicePicker, + sharingItems: createPostUrl() + ) + } Button(action: { publishPost(activePost) }, label: { Image(systemName: "paperplane") }) .disabled(activePost.body.isEmpty || activePost.status == PostStatus.published.rawValue) } } } + private func createPostUrl() -> [Any] { + guard let postId = activePost.postId else { return [] } + guard let urlString = activePost.slug != nil ? + "\(model.account.server)/\((activePost.collectionAlias)!)/\((activePost.slug)!)" : + "\(model.account.server)/\((postId))" else { return [] } + guard let data = URL(string: urlString) else { return [] } + return [data as NSURL] + } + private func publishPost(_ post: WFAPost) { DispatchQueue.main.async { LocalStorageManager().saveContext()