MainMigrationErrorView.swift 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // MainMigrationErrorView.swift
  3. // Trio
  4. //
  5. // Created by Cengiz Deniz on 21.04.25.
  6. //
  7. import SwiftUI
  8. extension Main {
  9. struct MainMigrationErrorView: View {
  10. let migrationErrors: [String]
  11. let onConfirm: () -> Void
  12. private let versionNumber = Bundle.main.releaseVersionNumber ?? String(localized: "Unknown")
  13. var body: some View {
  14. ZStack(alignment: .bottom) {
  15. LinearGradient(
  16. gradient: Gradient(colors: [Color.bgDarkBlue, Color.bgDarkerDarkBlue]),
  17. startPoint: .top,
  18. endPoint: .bottom
  19. )
  20. .ignoresSafeArea()
  21. ScrollView {
  22. VStack {
  23. Spacer().frame(maxHeight: 20)
  24. Image(.trioCircledNoBackground)
  25. .resizable()
  26. .scaledToFit()
  27. .frame(width: 80, height: 80)
  28. .shadow(color: Color.white.opacity(0.1), radius: 5, x: 0, y: 0)
  29. Text("Trio v\(versionNumber)")
  30. .fontWeight(.heavy)
  31. .foregroundStyle(Color(red: 148 / 255, green: 102 / 255, blue: 234 / 255))
  32. .padding(.vertical)
  33. Spacer().frame(maxHeight: 20)
  34. VStack(alignment: .leading, spacing: 20) {
  35. Text("Oops! Some data didn’t make it over.").font(.title3).bold()
  36. Text(
  37. "While upgrading Trio to the new version, we ran into an issue transferring some of your historical data."
  38. )
  39. .multilineTextAlignment(.leading)
  40. VStack(alignment: .leading, spacing: 10) {
  41. ForEach(migrationErrors, id: \.self) { message in
  42. BulletPoint(message)
  43. }
  44. }
  45. Text(
  46. "This means Trio may not have complete information about how much active insulin or carbs were still on board when you switched over."
  47. )
  48. .bold()
  49. VStack(alignment: .leading, spacing: 10) {
  50. HStack(alignment: .top, spacing: 10) {
  51. Image(systemName: "exclamationmark.triangle.fill")
  52. .foregroundStyle(Color.bgDarkBlue, Color.orange)
  53. .symbolRenderingMode(.palette)
  54. Text("To stay safe, we recommend:").foregroundStyle(Color.orange)
  55. }.bold()
  56. VStack(alignment: .leading, spacing: 10) {
  57. BulletPoint(
  58. String(
  59. localized: "Manually backdate some recent carbs or insulin you’ve entered in the last 6 to 8 hours."
  60. )
  61. )
  62. BulletPoint(
  63. String(
  64. localized: "Stay in open loop (no automated dosing) for a bit to help Trio catch up to keep you safe"
  65. )
  66. )
  67. }
  68. }
  69. .frame(maxWidth: .infinity)
  70. .padding()
  71. .background(Color.clear)
  72. .overlay(
  73. RoundedRectangle(cornerRadius: 10)
  74. .stroke(Color.orange, lineWidth: 2)
  75. )
  76. .cornerRadius(10)
  77. Text(
  78. "Trio is still fully functional and will adapt quickly — but your awareness right now helps it keep you safer."
  79. )
  80. .multilineTextAlignment(.leading)
  81. .padding(.bottom)
  82. }
  83. .padding(.horizontal, 24)
  84. .foregroundStyle(.white)
  85. }
  86. }
  87. .padding(.bottom, 80)
  88. Button(action: onConfirm) {
  89. Text("I understand! Proceed")
  90. .frame(width: UIScreen.main.bounds.width - 60, height: 50)
  91. .font(.title3).bold()
  92. .background(
  93. Capsule()
  94. .fill(Color.tabBar)
  95. )
  96. .foregroundColor(.white)
  97. .shadow(color: Color.black.opacity(0.1), radius: 5, x: 0, y: 2)
  98. }.padding(.bottom)
  99. }
  100. }
  101. }
  102. }
  103. struct MainMigrationErrorView_Previews: PreviewProvider {
  104. static var previews: some View {
  105. Group {
  106. Main.MainMigrationErrorView(
  107. migrationErrors: [
  108. "Failed to import glucose history.",
  109. "Failed to import pump history.",
  110. "Failed to import carb history.",
  111. "Failed to import algorithm data."
  112. ],
  113. onConfirm: { print("Proceed") }
  114. )
  115. }
  116. }
  117. }