URLTokenValidationView.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // LoopFollow
  2. // URLTokenValidationView.swift
  3. import SwiftUI
  4. struct URLTokenValidationView: View {
  5. let settings: RemoteCommandSettings
  6. let shouldPromptForURL: Bool
  7. let shouldPromptForToken: Bool
  8. let message: String
  9. let onConfirm: (RemoteCommandSettings) -> Void
  10. let onCancel: () -> Void
  11. init(
  12. settings: RemoteCommandSettings,
  13. shouldPromptForURL: Bool,
  14. shouldPromptForToken: Bool,
  15. message: String,
  16. onConfirm: @escaping (RemoteCommandSettings) -> Void,
  17. onCancel: @escaping () -> Void
  18. ) {
  19. self.settings = settings
  20. self.shouldPromptForURL = shouldPromptForURL
  21. self.shouldPromptForToken = shouldPromptForToken
  22. self.message = message
  23. self.onConfirm = onConfirm
  24. self.onCancel = onCancel
  25. }
  26. var body: some View {
  27. Form {
  28. Section {
  29. Text(message)
  30. .font(.body)
  31. .foregroundColor(.primary)
  32. }
  33. // Show URL section if we have URL data
  34. if !settings.url.isEmpty {
  35. Section(header: Text("Nightscout URL")) {
  36. HStack {
  37. Text("Current URL:")
  38. Spacer()
  39. Text(Storage.shared.url.value.isEmpty ? "Not set" : Storage.shared.url.value)
  40. .foregroundColor(.secondary)
  41. }
  42. HStack {
  43. Text("Scanned URL:")
  44. Spacer()
  45. Text(settings.url)
  46. .foregroundColor(.primary)
  47. }
  48. }
  49. }
  50. // Show token section if we have token data
  51. if !settings.token.isEmpty {
  52. Section(header: Text("Access Token")) {
  53. HStack {
  54. Text("Current Token:")
  55. Spacer()
  56. Text(Storage.shared.token.value.isEmpty ? "Not set" : "••••••••")
  57. .foregroundColor(.secondary)
  58. }
  59. HStack {
  60. Text("Scanned Token:")
  61. Spacer()
  62. Text("••••••••")
  63. .foregroundColor(.primary)
  64. }
  65. }
  66. }
  67. Section {
  68. HStack {
  69. Button("Cancel") {
  70. onCancel()
  71. }
  72. .buttonStyle(.bordered)
  73. Spacer()
  74. Button("Confirm & Import") {
  75. onConfirm(settings)
  76. }
  77. .buttonStyle(.borderedProminent)
  78. }
  79. }
  80. }
  81. .navigationTitle("URL/Token Validation")
  82. .navigationBarTitleDisplayMode(.inline)
  83. .navigationBarItems(trailing: Button("Cancel") {
  84. onCancel()
  85. })
  86. }
  87. }