mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Delete blank/untouched local draft from store when leaving editor
This commit is contained in:
parent
bf3d9ab6b9
commit
8e4957a389
@ -120,7 +120,6 @@ struct PostListView: View {
|
||||
managedPost.collectionAlias = selectedCollectionAlias
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
LocalStorageManager().saveContext()
|
||||
model.selectedPost = managedPost
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user