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 { var body: some View {
VStack { VStack {
TextField(post.title, text: $post.title) TextEditor(text: $post.title)
.border(Color.blue, width: 1)
.font(.title) .font(.title)
.multilineTextAlignment(.center) .frame(height: 100)
.padding(.bottom)
.onChange(of: post.title) { _ in .onChange(of: post.title) { _ in
if post.status == .published { if post.status == .published {
hasUnpublishedChanges = true hasUnpublishedChanges = true
} }
} }
TextEditor(text: $post.body) TextEditor(text: $post.body)
.border(Color.red, width: 1)
.font(.body) .font(.body)
.padding(.leading)
.onChange(of: post.body) { _ in .onChange(of: post.body) { _ in
if post.status == .published { if post.status == .published {
hasUnpublishedChanges = true hasUnpublishedChanges = true
} }
} }
.toolbar { }
if hasUnpublishedChanges { .padding()
PostStatusBadge(postStatus: .edited) .toolbar {
} else { if hasUnpublishedChanges {
PostStatusBadge(postStatus: post.status) PostStatusBadge(postStatus: .edited)
} } else {
} PostStatusBadge(postStatus: post.status)
}
} }
} }
} }