Page MenuHomeMusing Studio

No OneTemporary

diff --git a/Shared/PostEditor/PostEditorView.swift b/Shared/PostEditor/PostEditorView.swift
index 6077653..ece3dd7 100644
--- a/Shared/PostEditor/PostEditorView.swift
+++ b/Shared/PostEditor/PostEditorView.swift
@@ -1,87 +1,132 @@
import SwiftUI
struct PostEditorView: View {
+ @Environment(\.horizontalSizeClass) var horizontalSizeClass
@EnvironmentObject var model: WriteFreelyModel
@ObservedObject var post: Post
@State private var isNewPost = false
@State private var title = ""
var body: some View {
VStack {
- if post.hasNewerRemoteCopy {
- Text("⚠️ Newer copy on server")
- .font(.callout)
- }
TextEditor(text: $title)
.font(.title)
.frame(height: 100)
.onChange(of: title) { _ in
if post.status == .published && post.wfPost.title != title {
post.status = .edited
}
post.wfPost.title = title
}
TextEditor(text: $post.wfPost.body)
.font(.body)
.onChange(of: post.wfPost.body) { _ in
if post.status == .published {
post.status = .edited
}
}
}
.padding()
.toolbar {
ToolbarItem(placement: .status) {
- PostStatusBadgeView(post: post)
+ if post.hasNewerRemoteCopy {
+ if horizontalSizeClass == .compact {
+ VStack {
+ PostStatusBadgeView(post: post)
+ HStack {
+ Text("⚠️ Newer copy on server. Replace local copy?")
+ .font(.caption)
+ .foregroundColor(.secondary)
+ Button(action: {
+ model.updateFromServer(post: post)
+ }, label: {
+ Image(systemName: "square.and.arrow.down")
+ })
+ }
+ .padding(.bottom)
+ }
+ .padding(.top)
+ } else {
+ HStack {
+ PostStatusBadgeView(post: post)
+ .padding(.trailing)
+ Text("⚠️ Newer copy on server. Replace local copy?")
+ .font(.callout)
+ .foregroundColor(.secondary)
+ Button(action: {
+ model.updateFromServer(post: post)
+ }, label: {
+ Image(systemName: "square.and.arrow.down")
+ })
+ }
+ }
+ } else {
+ PostStatusBadgeView(post: post)
+ }
}
ToolbarItem(placement: .primaryAction) {
Button(action: {
model.publish(post: post)
post.status = .published
}, label: {
Image(systemName: "paperplane")
})
}
}
.onAppear(perform: {
title = post.wfPost.title ?? ""
checkIfNewPost()
if self.isNewPost {
addNewPostToStore()
}
})
.onDisappear(perform: {
if post.status == .edited {
DispatchQueue.main.async {
model.store.update(post)
}
}
})
}
private func checkIfNewPost() {
self.isNewPost = !model.store.posts.contains(where: { $0.id == post.id })
}
private func addNewPostToStore() {
withAnimation {
model.store.add(post)
self.isNewPost = false
}
}
}
struct PostEditorView_NewDraftPreviews: PreviewProvider {
static var previews: some View {
PostEditorView(post: Post())
.environmentObject(WriteFreelyModel())
}
}
-struct PostEditorView_ExistingPostPreviews: PreviewProvider {
+struct PostEditorView_NewerLocalPostPreviews: PreviewProvider {
+ static var previews: some View {
+ return PostEditorView(post: testPost)
+ .environmentObject(WriteFreelyModel())
+ }
+}
+
+struct PostEditorView_NewerRemotePostPreviews: PreviewProvider {
static var previews: some View {
- PostEditorView(post: testPostData[0])
+ let newerRemotePost = Post(
+ title: testPost.wfPost.title ?? "",
+ body: testPost.wfPost.body,
+ createdDate: testPost.wfPost.createdDate ?? Date(),
+ status: testPost.status,
+ collection: testPost.collection
+ )
+ newerRemotePost.hasNewerRemoteCopy = true
+ return PostEditorView(post: newerRemotePost)
.environmentObject(WriteFreelyModel())
}
}
diff --git a/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist b/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist
index 2723ebe..6cd8075 100644
--- a/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist
+++ b/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
- <integer>0</integer>
+ <integer>1</integer>
</dict>
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
- <integer>1</integer>
+ <integer>0</integer>
</dict>
</dict>
</dict>
</plist>

File Metadata

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

Event Timeline