Use TextEditor views for both title and body of PostEditor

This commit is contained in:
Angelo Stavrow 2020-07-28 13:36:33 -04:00
parent 4b4608709e
commit 85e99c720c
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -6,30 +6,31 @@ struct PostEditor: View {
var body: some View {
VStack {
TextField(post.title, text: $post.title)
TextEditor(text: $post.title)
.border(Color.blue, width: 1)
.font(.title)
.multilineTextAlignment(.center)
.padding(.bottom)
.frame(height: 100)
.onChange(of: post.title) { _ in
if post.status == .published {
hasUnpublishedChanges = true
}
}
TextEditor(text: $post.body)
.border(Color.red, width: 1)
.font(.body)
.padding(.leading)
.onChange(of: post.body) { _ in
if post.status == .published {
hasUnpublishedChanges = true
}
}
.toolbar {
if hasUnpublishedChanges {
PostStatusBadge(postStatus: .edited)
} else {
PostStatusBadge(postStatus: post.status)
}
}
}
.padding()
.toolbar {
if hasUnpublishedChanges {
PostStatusBadge(postStatus: .edited)
} else {
PostStatusBadge(postStatus: post.status)
}
}
}
}