Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F12725571
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
View Options
diff --git a/macOS/Navigation/ActivePostToolbarView.swift b/macOS/Navigation/ActivePostToolbarView.swift
index 991fb2c..417db66 100644
--- a/macOS/Navigation/ActivePostToolbarView.swift
+++ b/macOS/Navigation/ActivePostToolbarView.swift
@@ -1,43 +1,46 @@
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: {
self.isPresentingSharingServicePicker = true
},
label: { Image(systemName: "square.and.arrow.up") }
)
.disabled(activePost.status == PostStatus.local.rawValue)
.popover(isPresented: $isPresentingSharingServicePicker) {
- PostEditorSharingPicker(sharingItems: createPostUrl())
+ 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()
model.publish(post: post)
}
}
}
diff --git a/macOS/PostEditor/PostEditorSharingPicker.swift b/macOS/PostEditor/PostEditorSharingPicker.swift
index 97d2c99..02f7c96 100644
--- a/macOS/PostEditor/PostEditorSharingPicker.swift
+++ b/macOS/PostEditor/PostEditorSharingPicker.swift
@@ -1,37 +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
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Dec 20, 10:48 PM (16 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3550596
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment