Merge branch 'main' into add-move-post-ui

This commit is contained in:
Angelo Stavrow 2020-12-18 11:14:58 -05:00
commit 8a36de2b51
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 67 additions and 2 deletions

View File

@ -23,6 +23,7 @@
173E19D1254318F600440F0F /* RemoteChangePromptView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173E19D0254318F600440F0F /* RemoteChangePromptView.swift */; };
173E19E3254329CC00440F0F /* PostTextEditingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173E19E2254329CC00440F0F /* PostTextEditingView.swift */; };
17466626256C0D0600629997 /* MacEditorTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17466625256C0D0600629997 /* MacEditorTextView.swift */; };
17479F152583D8E40072B7FB /* PostEditorSharingPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17479F142583D8E40072B7FB /* PostEditorSharingPicker.swift */; };
17480CA5251272EE00EB7765 /* Bundle+AppVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17480CA4251272EE00EB7765 /* Bundle+AppVersion.swift */; };
17480CA6251272EE00EB7765 /* Bundle+AppVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17480CA4251272EE00EB7765 /* Bundle+AppVersion.swift */; };
174D313224EC2831006CA9EE /* WriteFreelyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174D313124EC2831006CA9EE /* WriteFreelyModel.swift */; };
@ -127,6 +128,7 @@
173E19D0254318F600440F0F /* RemoteChangePromptView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteChangePromptView.swift; sourceTree = "<group>"; };
173E19E2254329CC00440F0F /* PostTextEditingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostTextEditingView.swift; sourceTree = "<group>"; };
17466625256C0D0600629997 /* MacEditorTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacEditorTextView.swift; sourceTree = "<group>"; };
17479F142583D8E40072B7FB /* PostEditorSharingPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostEditorSharingPicker.swift; sourceTree = "<group>"; };
17480CA4251272EE00EB7765 /* Bundle+AppVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+AppVersion.swift"; sourceTree = "<group>"; };
174D313124EC2831006CA9EE /* WriteFreelyModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WriteFreelyModel.swift; sourceTree = "<group>"; };
1753F6AB24E431CC00309365 /* MacPreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacPreferencesView.swift; sourceTree = "<group>"; };
@ -313,6 +315,7 @@
17A67CAC251A5D8D002F163D /* PostEditor */ = {
isa = PBXGroup;
children = (
17479F142583D8E40072B7FB /* PostEditorSharingPicker.swift */,
17A67CAE251A5DD7002F163D /* PostEditorView.swift */,
17E5DF892543610700DCDC9B /* PostTextEditingView.swift */,
17466625256C0D0600629997 /* MacEditorTextView.swift */,
@ -758,6 +761,7 @@
17D435E924E3128F0036B539 /* PreferencesModel.swift in Sources */,
17120DAA24E1B2F5002B9F6C /* AccountLogoutView.swift in Sources */,
17DF32D624C8CA3400BCE2E3 /* PostStatusBadgeView.swift in Sources */,
17479F152583D8E40072B7FB /* PostEditorSharingPicker.swift in Sources */,
17480CA6251272EE00EB7765 /* Bundle+AppVersion.swift in Sources */,
17C42E662509237800072984 /* PostListFilteredView.swift in Sources */,
17120DAD24E1B99F002B9F6C /* AccountLoginView.swift in Sources */,

View File

@ -3,6 +3,7 @@ import SwiftUI
struct ActivePostToolbarView: View {
@EnvironmentObject var model: WriteFreelyModel
@ObservedObject var activePost: WFAPost
@State private var isPresentingSharingServicePicker: Bool = false
@State private var selectedCollection: WFACollection?
@ -67,8 +68,20 @@ struct ActivePostToolbarView: View {
.disabled(activePost.body.isEmpty)
} else {
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()
)
.frame(width: .zero, height: .zero)
}
Button(action: { publishPost(activePost) }, label: { Image(systemName: "paperplane") })
.disabled(activePost.body.isEmpty || activePost.status == PostStatus.published.rawValue)
}
@ -89,6 +102,15 @@ struct ActivePostToolbarView: View {
})
}
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()

View File

@ -0,0 +1,39 @@
import SwiftUI
struct PostEditorSharingPicker: NSViewRepresentable {
@Binding var isPresented: Bool
var sharingItems: [Any] = []
func makeNSView(context: Context) -> some NSView {
let view = NSView()
let picker = NSSharingServicePicker(items: sharingItems)
picker.delegate = context.coordinator
DispatchQueue.main.async {
picker.show(relativeTo: .zero, of: view, preferredEdge: .minY)
}
return view
}
func updateNSView(_ nsView: NSViewType, context: Context) {
}
func makeCoordinator() -> Coordinator {
Coordinator(owner: self)
}
class Coordinator: NSObject, NSSharingServicePickerDelegate {
let owner: PostEditorSharingPicker
init(owner: PostEditorSharingPicker) {
self.owner = owner
}
func sharingServicePicker(
_ sharingServicePicker: NSSharingServicePicker,
didChoose service: NSSharingService?
) {
sharingServicePicker.delegate = nil
self.owner.isPresented = false
}
}
}