Add new local draft to local store

This commit is contained in:
Angelo Stavrow 2020-09-08 10:34:20 -04:00
parent b2c503497d
commit 5436764e4f
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -32,8 +32,7 @@ struct PostListView: View {
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button(action: {
let post = Post()
model.store.add(post)
createNewLocalDraft()
}, label: {
Image(systemName: "square.and.pencil")
})
@ -90,8 +89,7 @@ struct PostListView: View {
.navigationSubtitle(pluralizedPostCount(for: showPosts(for: selectedCollection)))
.toolbar {
Button(action: {
let post = Post()
model.store.add(post)
createNewLocalDraft()
}, label: {
Image(systemName: "square.and.pencil")
})
@ -134,6 +132,19 @@ struct PostListView: View {
model.fetchUserPosts()
}
}
private func createNewLocalDraft() {
let post = Post()
let managedPost = WFAPost(context: PersistenceManager.persistentContainer.viewContext)
managedPost.createdDate = post.wfPost.createdDate
managedPost.title = post.wfPost.title
managedPost.body = post.wfPost.body
managedPost.status = 0
DispatchQueue.main.async {
model.store.add(post)
PersistenceManager().saveContext()
}
}
}
struct PostList_Previews: PreviewProvider {