Source code for the WriteFreely SwiftUI app for iOS, iPadOS, and macOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

88 rivejä
3.0 KiB

  1. import SwiftUI
  2. struct PostEditorStatusToolbarView: View {
  3. #if os(iOS)
  4. @Environment(\.horizontalSizeClass) var horizontalSizeClass
  5. #endif
  6. @EnvironmentObject var model: WriteFreelyModel
  7. @ObservedObject var post: WFAPost
  8. var body: some View {
  9. if post.hasNewerRemoteCopy {
  10. #if os(iOS)
  11. if horizontalSizeClass == .compact {
  12. VStack {
  13. PostStatusBadgeView(post: post)
  14. HStack {
  15. Text("⚠️ Newer copy on server. Replace local copy?")
  16. .font(.caption)
  17. .foregroundColor(.secondary)
  18. Button(action: {
  19. model.updateFromServer(post: post)
  20. }, label: {
  21. Image(systemName: "square.and.arrow.down")
  22. })
  23. }
  24. .padding(.bottom)
  25. }
  26. .padding(.top)
  27. } else {
  28. HStack {
  29. PostStatusBadgeView(post: post)
  30. .padding(.trailing)
  31. Text("⚠️ Newer copy on server. Replace local copy?")
  32. .font(.callout)
  33. .foregroundColor(.secondary)
  34. Button(action: {
  35. model.updateFromServer(post: post)
  36. }, label: {
  37. Image(systemName: "square.and.arrow.down")
  38. })
  39. }
  40. }
  41. #else
  42. HStack {
  43. PostStatusBadgeView(post: post)
  44. .padding(.trailing)
  45. Text("⚠️ Newer copy on server. Replace local copy?")
  46. .font(.callout)
  47. .foregroundColor(.secondary)
  48. Button(action: {
  49. model.updateFromServer(post: post)
  50. }, label: {
  51. Image(systemName: "square.and.arrow.down")
  52. })
  53. }
  54. #endif
  55. } else {
  56. PostStatusBadgeView(post: post)
  57. }
  58. }
  59. }
  60. struct PESTView_StandardPreviews: PreviewProvider {
  61. static var previews: some View {
  62. let context = LocalStorageManager.persistentContainer.viewContext
  63. let model = WriteFreelyModel()
  64. let testPost = WFAPost(context: context)
  65. testPost.status = PostStatus.published.rawValue
  66. return PostEditorStatusToolbarView(post: testPost)
  67. .environmentObject(model)
  68. }
  69. }
  70. struct PESTView_OutdatedLocalCopyPreviews: PreviewProvider {
  71. static var previews: some View {
  72. let context = LocalStorageManager.persistentContainer.viewContext
  73. let model = WriteFreelyModel()
  74. let testPost = WFAPost(context: context)
  75. testPost.status = PostStatus.published.rawValue
  76. testPost.hasNewerRemoteCopy = true
  77. return PostEditorStatusToolbarView(post: testPost)
  78. .environmentObject(model)
  79. }
  80. }