mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Update post in store async to avoid bad access error
This commit is contained in:
parent
00373e5a80
commit
201cc27162
@ -14,4 +14,15 @@ struct PostStore {
|
||||
mutating func purgeAllPosts() {
|
||||
posts = []
|
||||
}
|
||||
}
|
||||
|
||||
mutating func update(_ post: Post) {
|
||||
// Find the local copy in the store
|
||||
let localCopy = posts.first(where: { $0.id == post.id })
|
||||
|
||||
// If there's a local copy, update the updatedDate property of its WFPost
|
||||
if let localCopy = localCopy {
|
||||
localCopy.wfPost.updatedDate = Date()
|
||||
} else {
|
||||
print("local copy not found")
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,11 @@ struct PostEditorView: View {
|
||||
}
|
||||
})
|
||||
.onDisappear(perform: {
|
||||
post.wfPost.updatedDate = Date()
|
||||
if post.status == .edited {
|
||||
DispatchQueue.main.async {
|
||||
model.store.update(post)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user