Use Post.wfPost properties instead of redundant Post properties

This commit is contained in:
Angelo Stavrow 2020-08-26 13:17:48 -04:00
parent a97bd5abb7
commit d651776322
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 10 additions and 8 deletions

View File

@ -6,20 +6,21 @@ struct PostEditorView: View {
@ObservedObject var post: Post
@State private var isNewPost = false
@State private var title = ""
var body: some View {
VStack {
TextEditor(text: $post.title)
TextEditor(text: $title)
.font(.title)
.frame(height: 100)
.onChange(of: post.title) { _ in
if post.status == .published {
.onChange(of: title) { _ in
if post.status == .published && post.wfPost.title != title {
post.status = .edited
}
post.wfPost.title = title
}
TextEditor(text: $post.body)
TextEditor(text: $post.wfPost.body)
.font(.body)
.onChange(of: post.body) { _ in
.onChange(of: post.wfPost.body) { _ in
if post.status == .published {
post.status = .edited
}
@ -40,6 +41,7 @@ struct PostEditorView: View {
}
}
.onAppear(perform: {
title = post.wfPost.title ?? ""
checkIfNewPost()
if self.isNewPost {
addNewPostToStore()

View File

@ -6,10 +6,10 @@ struct PostCellView: View {
var body: some View {
HStack {
VStack(alignment: .leading) {
Text(post.title)
Text(post.wfPost.title ?? "")
.font(.headline)
.lineLimit(1)
Text(buildDateString(from: post.createdDate))
Text(buildDateString(from: post.wfPost.createdDate ?? Date()))
.font(.caption)
.lineLimit(1)
}