Page MenuHomeMusing Studio

No OneTemporary

diff --git a/Shared/Post/PostEditor.swift b/Shared/Post/PostEditor.swift
index 10a1713..8977c2e 100644
--- a/Shared/Post/PostEditor.swift
+++ b/Shared/Post/PostEditor.swift
@@ -1,62 +1,62 @@
import SwiftUI
struct PostEditor: View {
@EnvironmentObject var postStore: PostStore
@ObservedObject var post: Post
@State private var isNewPost = false
var body: some View {
VStack {
TextEditor(text: $post.title)
.font(.title)
.frame(height: 100)
.onChange(of: post.title) { _ in
if post.status == .published {
post.status = .edited
}
}
TextEditor(text: $post.body)
.font(.body)
.onChange(of: post.body) { _ in
if post.status == .published {
post.status = .edited
}
}
}
.padding()
.toolbar {
ToolbarItem(placement: .status) {
PostStatusBadge(post: post)
}
ToolbarItem(placement: .primaryAction) {
Button(action: {
- print("Publish button tapped!")
+ post.status = .published
}, label: {
Image(systemName: "paperplane")
})
}
}
.onAppear(perform: checkIfNewPost)
.onDisappear(perform: addPostToStore)
}
private func checkIfNewPost() {
if !postStore.posts.contains(where: { $0.id == post.id }) {
self.isNewPost = true
}
}
private func addPostToStore() {
if isNewPost {
withAnimation {
postStore.add(post)
}
}
}
}
struct PostEditor_Previews: PreviewProvider {
static var previews: some View {
PostEditor(post: testPost)
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Jan 20, 2:49 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3137538

Event Timeline