mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Show sharing service picker on button press
This commit is contained in:
parent
2a2628d9e4
commit
b8bbfbb208
@ -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>";
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user