2021-09-28 20:33:12 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
2021-10-23 11:51:02 +00:00
|
|
|
struct AccountValidationStatus: View {
|
2022-07-01 21:28:32 +00:00
|
|
|
@Binding var app: VideosApp?
|
2021-09-28 20:33:12 +00:00
|
|
|
@Binding var isValid: Bool
|
|
|
|
@Binding var isValidated: Bool
|
|
|
|
@Binding var isValidating: Bool
|
|
|
|
@Binding var error: String?
|
|
|
|
|
|
|
|
var body: some View {
|
2022-12-17 14:57:59 +00:00
|
|
|
VStack(alignment: .leading) {
|
|
|
|
HStack {
|
|
|
|
Image(systemName: validationStatusSystemImage)
|
|
|
|
.foregroundColor(validationStatusColor)
|
|
|
|
.imageScale(.medium)
|
|
|
|
.opacity(isValidating ? 1 : (isValidated ? 1 : 0))
|
2021-09-28 20:33:12 +00:00
|
|
|
|
2022-07-01 21:28:32 +00:00
|
|
|
Text(isValid ? "Connected successfully (\(app?.name ?? "Unknown"))" : "Connection failed")
|
2022-12-17 14:57:59 +00:00
|
|
|
.opacity(isValidated && !isValidating ? 1 : 0)
|
|
|
|
}
|
|
|
|
if errorVisible {
|
|
|
|
Text(error ?? "")
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
.lineLimit(nil)
|
|
|
|
.multilineTextAlignment(.leading)
|
|
|
|
.font(.footnote)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.padding(.top, 5)
|
|
|
|
.opacity(errorTextVisible ? 1 : 0)
|
2021-09-28 20:33:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-17 14:57:59 +00:00
|
|
|
var errorVisible: Bool {
|
|
|
|
#if !os(iOS)
|
|
|
|
true
|
|
|
|
#else
|
|
|
|
errorTextVisible
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
var errorTextVisible: Bool {
|
|
|
|
error != nil && isValidated && !isValid && !isValidating
|
|
|
|
}
|
|
|
|
|
2021-09-28 20:33:12 +00:00
|
|
|
var validationStatusSystemImage: String {
|
|
|
|
if isValidating {
|
|
|
|
return "bolt.horizontal.fill"
|
|
|
|
}
|
2023-06-17 12:09:51 +00:00
|
|
|
|
|
|
|
return isValid ? "checkmark.circle.fill" : "xmark.circle.fill"
|
2021-09-28 20:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var validationStatusColor: Color {
|
|
|
|
if isValidating {
|
|
|
|
return .accentColor
|
|
|
|
}
|
2023-06-17 12:09:51 +00:00
|
|
|
|
|
|
|
return isValid ? .green : .red
|
2021-09-28 20:33:12 +00:00
|
|
|
}
|
|
|
|
}
|