URLTokenValidationView.swift 3.0 KB

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