Show sharing service picker on button press

This commit is contained in:
Angelo Stavrow 2020-12-11 14:44:20 -05:00
parent 2a2628d9e4
commit b8bbfbb208
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 22 additions and 3 deletions

View File

@ -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 = "<group>";

View File

@ -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()