mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Add single-post updateFromServer API to WriteFreelyModel
This commit is contained in:
parent
b21cef6a54
commit
16b16dbd52
@ -100,6 +100,15 @@ extension WriteFreelyModel {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func updateFromServer(post: Post) {
|
||||
guard let loggedInClient = client else { return }
|
||||
guard let postId = post.wfPost.postId else { return }
|
||||
DispatchQueue.main.async {
|
||||
self.selectedPost = post
|
||||
}
|
||||
loggedInClient.getPost(byId: postId, completion: updateFromServerHandler)
|
||||
}
|
||||
}
|
||||
|
||||
private extension WriteFreelyModel {
|
||||
@ -208,9 +217,6 @@ private extension WriteFreelyModel {
|
||||
post = Post(wfPost: fetchedPost)
|
||||
}
|
||||
fetchedPostsArray.append(post)
|
||||
// DispatchQueue.main.async {
|
||||
// self.store.add(post)
|
||||
// }
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
self.store.updateStore(with: fetchedPostsArray)
|
||||
@ -234,6 +240,18 @@ private extension WriteFreelyModel {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
|
||||
func updateFromServerHandler(result: Result<WFPost, Error>) {
|
||||
do {
|
||||
let fetchedPost = try result.get()
|
||||
DispatchQueue.main.async {
|
||||
guard let selectedPost = self.selectedPost else { return }
|
||||
self.store.replace(post: selectedPost, with: fetchedPost)
|
||||
}
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension WriteFreelyModel {
|
||||
|
Loading…
Reference in New Issue
Block a user