mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Ensure we don't nil out the collection alias on updating from server
This commit is contained in:
parent
a20b2911b7
commit
089a12dcb2
@ -112,7 +112,12 @@ extension WriteFreelyModel {
|
||||
DispatchQueue.main.async {
|
||||
self.selectedPost = post
|
||||
}
|
||||
loggedInClient.getPost(byId: postId, completion: updateFromServerHandler)
|
||||
if let postCollectionAlias = post.collectionAlias,
|
||||
let postSlug = post.slug {
|
||||
loggedInClient.getPost(bySlug: postSlug, from: postCollectionAlias, completion: updateFromServerHandler)
|
||||
} else {
|
||||
loggedInClient.getPost(byId: postId, completion: updateFromServerHandler)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,12 +285,15 @@ private extension WriteFreelyModel {
|
||||
}
|
||||
|
||||
func updateFromServerHandler(result: Result<WFPost, Error>) {
|
||||
// ⚠️ NOTE:
|
||||
// The API does not return a collection alias, so we take care not to overwrite the
|
||||
// cached post's collection alias with the 'nil' value from the fetched post.
|
||||
// See: https://github.com/writeas/writefreely-swift/issues/20
|
||||
do {
|
||||
let fetchedPost = try result.get()
|
||||
guard let cachedPost = self.selectedPost else { return }
|
||||
cachedPost.appearance = fetchedPost.appearance
|
||||
cachedPost.body = fetchedPost.body
|
||||
cachedPost.collectionAlias = fetchedPost.collectionAlias
|
||||
cachedPost.createdDate = fetchedPost.createdDate
|
||||
cachedPost.language = fetchedPost.language
|
||||
cachedPost.postId = fetchedPost.postId
|
||||
|
Loading…
Reference in New Issue
Block a user