Move server-update warnings from toolbar on iOS

This commit is contained in:
Angelo Stavrow 2020-09-29 12:35:51 -04:00
parent 25c1009136
commit bc4c43f40c
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 41 additions and 72 deletions

View File

@ -1,10 +1,6 @@
import SwiftUI
struct PostEditorStatusToolbarView: View {
#if os(iOS)
@Environment(\.horizontalSizeClass) var horizontalSizeClass
@Environment(\.presentationMode) var presentationMode
#endif
@EnvironmentObject var model: WriteFreelyModel
@ObservedObject var post: WFAPost
@ -12,36 +8,7 @@ struct PostEditorStatusToolbarView: View {
var body: some View {
if post.hasNewerRemoteCopy {
#if os(iOS)
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")
})
}
}
PostStatusBadgeView(post: post)
#else
HStack {
PostStatusBadgeView(post: post)
@ -58,45 +25,12 @@ struct PostEditorStatusToolbarView: View {
#endif
} else if post.wasDeletedFromServer && post.status != PostStatus.local.rawValue {
#if os(iOS)
if horizontalSizeClass == .compact {
VStack {
PostStatusBadgeView(post: post)
HStack {
Text("‼️ Post deleted from server. Delete local copy?")
.font(.caption)
.foregroundColor(.secondary)
Button(action: {
self.presentationMode.wrappedValue.dismiss()
model.selectedPost = nil
model.posts.remove(post)
}, label: {
Image(systemName: "trash")
})
}
.padding(.bottom)
}
.padding(.top)
} else {
HStack {
PostStatusBadgeView(post: post)
.padding(.trailing)
Text("‼️ Post deleted from server. Delete local copy?")
.font(.callout)
.foregroundColor(.secondary)
Button(action: {
self.presentationMode.wrappedValue.dismiss()
model.selectedPost = nil
model.posts.remove(post)
}, label: {
Image(systemName: "trash")
})
}
}
PostStatusBadgeView(post: post)
#else
HStack {
PostStatusBadgeView(post: post)
.padding(.trailing)
Text(" Post deleted from server. Delete local copy?")
Text("⚠️ Post deleted from server. Delete local copy?")
.font(.callout)
.foregroundColor(.secondary)
Button(action: {

View File

@ -7,12 +7,12 @@
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>

View File

@ -2,11 +2,45 @@ import SwiftUI
struct PostEditorView: View {
@EnvironmentObject var model: WriteFreelyModel
@Environment(\.horizontalSizeClass) var horizontalSizeClass
@Environment(\.presentationMode) var presentationMode
@ObservedObject var post: WFAPost
var body: some View {
VStack {
if post.hasNewerRemoteCopy {
HStack {
Text("⚠️ Newer copy on server. Replace local copy?")
.font(horizontalSizeClass == .compact ? .caption : .body)
.foregroundColor(.secondary)
Button(action: {
model.updateFromServer(post: post)
}, label: {
Image(systemName: "square.and.arrow.down")
})
}
.padding(EdgeInsets(top: 10, leading: 20, bottom: 10, trailing: 20))
.background(Color(UIColor.secondarySystemBackground))
.clipShape(Capsule())
.padding(.bottom)
} else if post.wasDeletedFromServer {
HStack {
Text("⚠️ Post deleted from server. Delete local copy?")
.font(horizontalSizeClass == .compact ? .caption : .body)
.foregroundColor(.secondary)
Button(action: {
self.presentationMode.wrappedValue.dismiss()
model.selectedPost = nil
model.posts.remove(post)
}, label: {
Image(systemName: "trash")
})
}
.padding(EdgeInsets(top: 10, leading: 20, bottom: 10, trailing: 20))
.background(Color(UIColor.secondarySystemBackground))
.clipShape(Capsule())
.padding(.bottom)
}
switch post.appearance {
case "sans":
TextField("Title (optional)", text: $post.title)
@ -197,6 +231,7 @@ struct PostEditorView_ExistingPostPreviews: PreviewProvider {
testPost.body = "Here's some cool sample body text."
testPost.createdDate = Date()
testPost.appearance = "code"
testPost.hasNewerRemoteCopy = true
let model = WriteFreelyModel()