Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F13892282
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
View Options
diff --git a/Shared/Post/Post.swift b/Shared/Post/Post.swift
index 53dc52c..289b7bf 100644
--- a/Shared/Post/Post.swift
+++ b/Shared/Post/Post.swift
@@ -1,46 +1,59 @@
import Foundation
import WriteFreely
-struct Post: Identifiable {
- var id = UUID()
- var title: String = "Title"
- var body: String = "Write your post here..."
- var createdDate: Date = Date()
- var status: PostStatus = .draft
+class Post: Identifiable, ObservableObject {
+ @Published var title: String
+ @Published var body: String
+ @Published var createdDate: Date
+ @Published var status: PostStatus
+
+ let id = UUID()
+
+ init(
+ title: String = "Title",
+ body: String = "Write your post here...",
+ createdDate: Date = Date(),
+ status: PostStatus = .draft
+ ) {
+ self.title = title
+ self.body = body
+ self.createdDate = createdDate
+ self.status = status
+ }
}
let testPost = Post(
title: "Test Post Title",
body: """
Here's some cool sample body text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ultrices \
posuere dignissim. Vestibulum a libero tempor, lacinia nulla vitae, congue purus. Nunc ac nulla quam. Duis \
tincidunt eros augue, et volutpat tortor pulvinar ut. Nullam sit amet maximus urna. Phasellus non dignissim lacus.\
Nulla ac posuere ex. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec \
non molestie mauris. Suspendisse potenti. Vivamus at erat turpis.
Pellentesque porttitor gravida tincidunt. Sed vitae eros non metus aliquam hendrerit. Aliquam sed risus suscipit \
turpis dictum dictum. Duis lacus lectus, dictum vel felis in, rhoncus fringilla felis. Nunc id dolor nisl. Aliquam \
euismod purus elit. Nullam egestas neque leo, sed aliquet ligula ultrices nec.
""",
createdDate: Date(),
status: .published)
let testPostData = [
Post(
title: "My First Post",
body: "Look at me, creating a first post! That's cool.",
createdDate: Date(timeIntervalSince1970: 1595429452),
status: .published
),
Post(
title: "Post 2: The Quickening",
body: "See, here's the rule about Highlander jokes: _there can be only one_.",
createdDate: Date(timeIntervalSince1970: 1595514125),
status: .edited
),
Post(
title: "The Post Revolutions",
body: "I can never keep the Matrix movie order straight. Why not just call them part 2 and part 3?",
createdDate: Date(timeIntervalSince1970: 1595600006)
)
]
diff --git a/Shared/Post/PostEditor.swift b/Shared/Post/PostEditor.swift
index c689aaa..a3dbcfe 100644
--- a/Shared/Post/PostEditor.swift
+++ b/Shared/Post/PostEditor.swift
@@ -1,41 +1,41 @@
import SwiftUI
struct PostEditor: View {
- @State var post: Post
+ @ObservedObject var post: Post
@State private var hasUnpublishedChanges: Bool = false
var body: some View {
VStack {
TextField(post.title, text: $post.title)
.font(.title)
.multilineTextAlignment(.center)
.padding(.bottom)
.onChange(of: post.title) { _ in
if post.status == .published {
hasUnpublishedChanges = true
}
}
TextEditor(text: $post.body)
.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)
}
}
}
}
}
struct PostEditor_Previews: PreviewProvider {
static var previews: some View {
PostEditor(post: testPost)
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Mar 12, 6:35 AM (27 m, 12 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3653087
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment