mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Use optional unwrapping and wfPost properties in publish API/handler
This commit is contained in:
parent
072e60c918
commit
a97bd5abb7
@ -66,30 +66,17 @@ extension WriteFreelyModel {
|
||||
func publish(post: Post) {
|
||||
guard let loggedInClient = client else { return }
|
||||
|
||||
if post.wfPost == nil {
|
||||
// This is a new local draft.
|
||||
post.wfPost = WFPost(
|
||||
body: post.body,
|
||||
title: post.title,
|
||||
createdDate: post.createdDate
|
||||
)
|
||||
loggedInClient.createPost(
|
||||
post: post.wfPost!, in: post.collection.wfCollection?.alias, completion: publishHandler
|
||||
if let existingPostId = post.wfPost.postId {
|
||||
// This is an existing post.
|
||||
loggedInClient.updatePost(
|
||||
postId: existingPostId,
|
||||
updatedPost: post.wfPost,
|
||||
completion: publishHandler
|
||||
)
|
||||
} else {
|
||||
// This is an existing post.
|
||||
// 1. Update Post.wfPost properties from (redundant) Post properties
|
||||
// FIXME: https://github.com/writeas/writefreely-swiftui-multiplatform/issues/27
|
||||
guard var publishedPost = post.wfPost else { return }
|
||||
publishedPost.title = post.title
|
||||
publishedPost.body = post.body
|
||||
publishedPost.createdDate = post.createdDate
|
||||
|
||||
// 2. Update the post on the server and call the handler
|
||||
loggedInClient.updatePost(
|
||||
postId: publishedPost.postId!,
|
||||
updatedPost: publishedPost,
|
||||
completion: publishHandler
|
||||
// This is a new local draft.
|
||||
loggedInClient.createPost(
|
||||
post: post.wfPost, in: post.collection.wfCollection?.alias, completion: publishHandler
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -212,7 +199,7 @@ private extension WriteFreelyModel {
|
||||
do {
|
||||
let wfPost = try result.get()
|
||||
let foundPostIndex = store.posts.firstIndex(where: {
|
||||
$0.title == wfPost.title && $0.body == wfPost.body
|
||||
$0.wfPost.title == wfPost.title && $0.wfPost.body == wfPost.body
|
||||
})
|
||||
guard let index = foundPostIndex else { return }
|
||||
DispatchQueue.main.async {
|
||||
|
Loading…
Reference in New Issue
Block a user