Check that we're working with model's selectedPost property

This commit is contained in:
Angelo Stavrow 2021-01-27 10:37:18 -05:00
parent f948a16ad0
commit f589d42794
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -64,7 +64,7 @@ struct ActivePostToolbarView: View {
}, label: { }, label: {
Label("Publish…", systemImage: "paperplane") Label("Publish…", systemImage: "paperplane")
}) })
.disabled(model.selectedPost!.body.isEmpty) .disabled(model.selectedPost?.body.isEmpty ?? true)
.help("Publish the post to the web.\(model.account.isLoggedIn ? "" : " You must be logged in to do this.")") // swiftlint:disable:this line_length .help("Publish the post to the web.\(model.account.isLoggedIn ? "" : " You must be logged in to do this.")") // swiftlint:disable:this line_length
} else { } else {
HStack(spacing: 4) { HStack(spacing: 4) {
@ -114,6 +114,9 @@ struct ActivePostToolbarView: View {
} }
private func publishPost(_ post: WFAPost) { private func publishPost(_ post: WFAPost) {
if post != model.selectedPost {
return
}
DispatchQueue.main.async { DispatchQueue.main.async {
LocalStorageManager().saveContext() LocalStorageManager().saveContext()
model.publish(post: post) model.publish(post: post)