mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Add PostStore method to update post's WFPost property
This commit is contained in:
parent
30b527daa4
commit
4ae66e1585
@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import WriteFreely
|
||||
|
||||
struct PostStore {
|
||||
var posts: [Post]
|
||||
@ -23,7 +24,23 @@ struct PostStore {
|
||||
if let localCopy = localCopy {
|
||||
localCopy.wfPost.updatedDate = Date()
|
||||
} else {
|
||||
print("local copy not found")
|
||||
print("Error: Local copy not found")
|
||||
}
|
||||
}
|
||||
|
||||
mutating func replace(post: Post, with fetchedPost: WFPost) {
|
||||
// Find the local copy in the store.
|
||||
let localCopy = posts.first(where: { $0.id == post.id })
|
||||
|
||||
// Replace the local copy's wfPost property with the fetched copy.
|
||||
if let localCopy = localCopy {
|
||||
localCopy.wfPost = fetchedPost
|
||||
DispatchQueue.main.async {
|
||||
localCopy.hasNewerRemoteCopy = false
|
||||
localCopy.status = .published
|
||||
}
|
||||
} else {
|
||||
print("Error: Local copy not found")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user