1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 14:50:32 +05:30
yattee/Shared/Settings/AccountValidationStatus.swift

63 lines
1.8 KiB
Swift
Raw Normal View History

import Foundation
import SwiftUI
2021-10-23 17:21:02 +05:30
struct AccountValidationStatus: View {
@Binding var app: VideosApp?
@Binding var isValid: Bool
@Binding var isValidated: Bool
@Binding var isValidating: Bool
@Binding var error: String?
var body: some View {
VStack(alignment: .leading) {
HStack {
Image(systemName: validationStatusSystemImage)
.foregroundColor(validationStatusColor)
.imageScale(.medium)
.opacity(isValidating ? 1 : (isValidated ? 1 : 0))
Text(isValid ? "Connected successfully (\(app?.name ?? "Unknown"))" : "Connection failed")
.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)
}
}
}
var errorVisible: Bool {
#if !os(iOS)
true
#else
errorTextVisible
#endif
}
var errorTextVisible: Bool {
error != nil && isValidated && !isValid && !isValidating
}
var validationStatusSystemImage: String {
if isValidating {
return "bolt.horizontal.fill"
} else {
return isValid ? "checkmark.circle.fill" : "xmark.circle.fill"
}
}
var validationStatusColor: Color {
if isValidating {
return .accentColor
} else {
return isValid ? .green : .red
}
}
}