Clear lastDraft if selectedPost has published status

This commit is contained in:
Angelo Stavrow 2020-09-24 14:13:32 -04:00
parent 5bcd3185bf
commit 44fd09aa33
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 13 additions and 1 deletions

View File

@ -15,7 +15,11 @@ class WriteFreelyModel: ObservableObject {
@Published var selectedPost: WFAPost? {
didSet {
if let post = selectedPost {
if post.status != PostStatus.published.rawValue { editor.setLastDraft(post) }
if post.status != PostStatus.published.rawValue {
editor.setLastDraft(post)
} else {
editor.clearLastDraft()
}
} else {
editor.clearLastDraft()
}

View File

@ -111,6 +111,10 @@ struct PostEditorView: View {
DispatchQueue.main.async {
model.editor.setLastDraft(post)
}
} else {
DispatchQueue.main.async {
model.editor.clearLastDraft()
}
}
})
.onDisappear(perform: {

View File

@ -140,6 +140,10 @@ struct PostEditorView: View {
DispatchQueue.main.async {
LocalStorageManager().saveContext()
}
} else {
DispatchQueue.main.async {
model.editor.clearLastDraft()
}
}
})
}