mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Add new local draft to local store
This commit is contained in:
parent
b2c503497d
commit
5436764e4f
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user