Delete blank/untouched local draft from store when leaving editor

This commit is contained in:
Angelo Stavrow 2020-09-24 16:17:56 -04:00
parent bf3d9ab6b9
commit 8e4957a389
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
4 changed files with 28 additions and 11 deletions

View File

@ -120,7 +120,6 @@ struct PostListView: View {
managedPost.collectionAlias = selectedCollectionAlias
}
DispatchQueue.main.async {
LocalStorageManager().saveContext()
model.selectedPost = managedPost
}
}

View File

@ -7,12 +7,12 @@
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>

View File

@ -118,7 +118,16 @@ struct PostEditorView: View {
}
})
.onDisappear(perform: {
if post.status != PostStatus.published.rawValue {
if post.title.count == 0
&& post.body.count == 0
&& post.status == PostStatus.local.rawValue
&& post.updatedDate == nil
&& post.postId == nil {
withAnimation {
model.posts.remove(post)
model.posts.loadCachedPosts()
}
} else if post.status != PostStatus.published.rawValue {
DispatchQueue.main.async {
LocalStorageManager().saveContext()
}

View File

@ -133,19 +133,28 @@ struct PostEditorView: View {
DispatchQueue.main.async {
model.editor.setLastDraft(post)
}
}
})
.onDisappear(perform: {
if post.status != PostStatus.published.rawValue {
DispatchQueue.main.async {
LocalStorageManager().saveContext()
}
} else {
DispatchQueue.main.async {
model.editor.clearLastDraft()
}
}
})
.onDisappear(perform: {
if post.title.count == 0
&& post.body.count == 0
&& post.status == PostStatus.local.rawValue
&& post.updatedDate == nil
&& post.postId == nil {
withAnimation {
model.posts.remove(post)
model.posts.loadCachedPosts()
}
} else if post.status != PostStatus.published.rawValue {
DispatchQueue.main.async {
LocalStorageManager().saveContext()
}
}
})
}
private func publishPost() {