Make sure to always clear the last draft when we unset the selectedPost

This commit is contained in:
Angelo Stavrow 2020-11-26 17:01:33 -05:00
parent 5dabe97db4
commit 28d3b6f831
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 14 additions and 2 deletions

View File

@ -118,7 +118,9 @@ struct ContentView: View {
.alert(isPresented: $model.isPresentingNetworkErrorAlert, content: {
Alert(
title: Text("Connection Error"),
message: Text("There is no internet connection at the moment. Please reconnect or try again later."),
message: Text("""
There is no internet connection at the moment. Please reconnect or try again later.
"""),
dismissButton: .default(Text("OK"), action: {
model.isPresentingNetworkErrorAlert = false
})

View File

@ -94,6 +94,7 @@ struct PostListFilteredView: View {
if let postToDelete = model.postToDelete {
model.selectedPost = nil
DispatchQueue.main.async {
model.editor.clearLastDraft()
model.posts.remove(postToDelete)
}
model.postToDelete = nil
@ -122,7 +123,10 @@ struct PostListFilteredView: View {
func delete(_ post: WFAPost) {
DispatchQueue.main.async {
model.selectedPost = nil
if post == model.selectedPost {
model.selectedPost = nil
model.editor.clearLastDraft()
}
model.posts.remove(post)
}
}

View File

@ -86,6 +86,12 @@ struct PostListView: View {
)
)
.navigationSubtitle(postCount == 1 ? "\(postCount) post" : "\(postCount) posts")
.onChange(of: selectedCollection, perform: { _ in
DispatchQueue.main.async {
self.model.selectedPost = nil
self.model.editor.clearLastDraft()
}
})
#endif
}
}