Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F13799785
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Subscribers
None
View Options
diff --git a/macOS/PostEditor/PostEditorView.swift b/macOS/PostEditor/PostEditorView.swift
index d662bcd..ff82a93 100644
--- a/macOS/PostEditor/PostEditorView.swift
+++ b/macOS/PostEditor/PostEditorView.swift
@@ -1,105 +1,113 @@
import SwiftUI
struct PostEditorView: View {
@EnvironmentObject var model: WriteFreelyModel
@EnvironmentObject var errorHandling: ErrorHandling
@ObservedObject var post: WFAPost
@State private var isHovering: Bool = false
@State private var updatingFromServer: Bool = false
var body: some View {
- PostTextEditingView(
- post: post,
- updatingFromServer: $updatingFromServer
- )
- .background(Color(NSColor.controlBackgroundColor))
- .onAppear(perform: {
- model.editor.setInitialValues(for: post)
- if post.status != PostStatus.published.rawValue {
- DispatchQueue.main.async {
- self.model.editor.saveLastDraft(post)
- }
- } else {
- self.model.editor.clearLastDraft()
- }
- })
- .onChange(of: post.hasNewerRemoteCopy, perform: { _ in
- if !post.hasNewerRemoteCopy {
- self.updatingFromServer = true
- }
- })
- .onChange(of: post.status, perform: { value in
- if value != PostStatus.published.rawValue {
- self.model.editor.saveLastDraft(post)
- } else {
- self.model.editor.clearLastDraft()
+ VStack {
+ if !model.hasNetworkConnection {
+ Label("You are not connected to the internet", systemImage: "wifi.exclamationmark")
+ .font(.caption)
+ .foregroundColor(.secondary)
+ .padding(.top, 8)
}
- DispatchQueue.main.async {
- LocalStorageManager.standard.saveContext()
- }
- })
- .onChange(of: model.hasError) { value in
- if value {
- if model.hasNetworkConnection {
- if let error = model.currentError {
- self.errorHandling.handle(error: error)
- } else {
- self.errorHandling.handle(error: AppError.genericError())
+ PostTextEditingView(
+ post: post,
+ updatingFromServer: $updatingFromServer
+ )
+ .background(Color(NSColor.controlBackgroundColor))
+ .onAppear(perform: {
+ model.editor.setInitialValues(for: post)
+ if post.status != PostStatus.published.rawValue {
+ DispatchQueue.main.async {
+ self.model.editor.saveLastDraft(post)
}
+ } else {
+ self.model.editor.clearLastDraft()
}
- model.hasError = false
- }
- }
- .onDisappear(perform: {
- DispatchQueue.main.async {
- model.editor.clearLastDraft()
- }
- if post.title.count == 0
- && post.body.count == 0
- && post.status == PostStatus.local.rawValue
- && post.updatedDate == nil
- && post.postId == nil {
- DispatchQueue.main.async {
- model.posts.remove(post)
+ })
+ .onChange(of: post.hasNewerRemoteCopy, perform: { _ in
+ if !post.hasNewerRemoteCopy {
+ self.updatingFromServer = true
+ }
+ })
+ .onChange(of: post.status, perform: { value in
+ if value != PostStatus.published.rawValue {
+ self.model.editor.saveLastDraft(post)
+ } else {
+ self.model.editor.clearLastDraft()
}
- } else if post.status != PostStatus.published.rawValue {
DispatchQueue.main.async {
LocalStorageManager.standard.saveContext()
}
+ })
+ .onChange(of: model.hasError) { value in
+ if value {
+ if model.hasNetworkConnection {
+ if let error = model.currentError {
+ self.errorHandling.handle(error: error)
+ } else {
+ self.errorHandling.handle(error: AppError.genericError())
+ }
+ }
+ model.hasError = false
+ }
}
- })
+ .onDisappear(perform: {
+ DispatchQueue.main.async {
+ model.editor.clearLastDraft()
+ }
+ if post.title.count == 0
+ && post.body.count == 0
+ && post.status == PostStatus.local.rawValue
+ && post.updatedDate == nil
+ && post.postId == nil {
+ DispatchQueue.main.async {
+ model.posts.remove(post)
+ }
+ } else if post.status != PostStatus.published.rawValue {
+ DispatchQueue.main.async {
+ LocalStorageManager.standard.saveContext()
+ }
+ }
+ })
+ }
}
}
struct PostEditorView_EmptyPostPreviews: PreviewProvider {
static var previews: some View {
let context = LocalStorageManager.standard.container.viewContext
let testPost = WFAPost(context: context)
testPost.createdDate = Date()
testPost.appearance = "norm"
let model = WriteFreelyModel()
return PostEditorView(post: testPost)
.environment(\.managedObjectContext, context)
.environmentObject(model)
}
}
struct PostEditorView_ExistingPostPreviews: PreviewProvider {
static var previews: some View {
let context = LocalStorageManager.standard.container.viewContext
let testPost = WFAPost(context: context)
testPost.title = "Test Post Title"
testPost.body = "Here's some cool sample body text."
testPost.createdDate = Date()
testPost.appearance = "code"
let model = WriteFreelyModel()
return PostEditorView(post: testPost)
.environment(\.managedObjectContext, context)
.environmentObject(model)
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Feb 6, 7:39 PM (22 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3616891
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment