mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 13:33:42 +00:00
Instance and account form and validation improvements
This commit is contained in:
parent
9f3a94137c
commit
cf0572a94b
@ -82,14 +82,24 @@ final class AccountValidator: Service {
|
||||
}
|
||||
|
||||
guard !response.json.isEmpty else {
|
||||
guard let app = self.appsToValidateInstance.popLast() else {
|
||||
if app == .piped {
|
||||
if response.text.contains("property=\"og:title\" content=\"Piped\"") {
|
||||
self.isValid.wrappedValue = false
|
||||
self.isValidated.wrappedValue = true
|
||||
self.isValidating.wrappedValue = false
|
||||
self.error?.wrappedValue = "Trying to use Piped front-end URL, you need to use URL for Piped API instead"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
guard let nextApp = self.appsToValidateInstance.popLast() else {
|
||||
self.isValid.wrappedValue = false
|
||||
self.isValidated.wrappedValue = true
|
||||
self.isValidating.wrappedValue = false
|
||||
return
|
||||
}
|
||||
|
||||
self.tryValidatingUsing(app)
|
||||
self.tryValidatingUsing(nextApp)
|
||||
return
|
||||
}
|
||||
|
||||
@ -128,15 +138,15 @@ final class AccountValidator: Service {
|
||||
|
||||
switch app.wrappedValue {
|
||||
case .invidious:
|
||||
invidiousValidation()
|
||||
validateInvidiousAccount()
|
||||
case .piped:
|
||||
pipedValidation()
|
||||
validatePipedAccount()
|
||||
default:
|
||||
setValidationResult(false)
|
||||
}
|
||||
}
|
||||
|
||||
func invidiousValidation() {
|
||||
func validateInvidiousAccount() {
|
||||
guard let username = account?.username,
|
||||
let password = account?.password
|
||||
else {
|
||||
@ -177,7 +187,7 @@ final class AccountValidator: Service {
|
||||
}
|
||||
}
|
||||
|
||||
func pipedValidation() {
|
||||
func validatePipedAccount() {
|
||||
guard let request = accountRequest else {
|
||||
setValidationResult(false)
|
||||
|
||||
|
@ -24,6 +24,13 @@ struct AccountForm: View {
|
||||
Group {
|
||||
header
|
||||
form
|
||||
#if os(macOS)
|
||||
VStack {
|
||||
validationStatus
|
||||
}
|
||||
.frame(minHeight: 60, alignment: .topLeading)
|
||||
.padding(.horizontal, 15)
|
||||
#endif
|
||||
footer
|
||||
}
|
||||
.frame(maxWidth: 1000)
|
||||
@ -34,7 +41,8 @@ struct AccountForm: View {
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
||||
.background(Color.background(scheme: colorScheme))
|
||||
#else
|
||||
.frame(width: 400, height: 145)
|
||||
.frame(width: 400, height: 180)
|
||||
.padding(.vertical)
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -72,24 +80,23 @@ struct AccountForm: View {
|
||||
.onChange(of: password) { _ in validate() }
|
||||
}
|
||||
|
||||
var formFields: some View {
|
||||
Group {
|
||||
@ViewBuilder var formFields: some View {
|
||||
TextField("Username", text: $username)
|
||||
SecureField("Password", text: $password)
|
||||
|
||||
#if os(tvOS)
|
||||
VStack {
|
||||
validationStatus
|
||||
}
|
||||
.frame(minHeight: 100)
|
||||
#elseif os(iOS)
|
||||
validationStatus
|
||||
#endif
|
||||
}
|
||||
|
||||
var usernamePrompt: String {
|
||||
switch instance.app {
|
||||
case .invidious:
|
||||
return "SID Cookie"
|
||||
default:
|
||||
return "Username"
|
||||
}
|
||||
}
|
||||
|
||||
var footer: some View {
|
||||
HStack {
|
||||
@ViewBuilder var validationStatus: some View {
|
||||
if !username.isEmpty && !password.isEmpty {
|
||||
Section {
|
||||
AccountValidationStatus(
|
||||
app: .constant(instance.app),
|
||||
isValid: $isValid,
|
||||
@ -97,7 +104,12 @@ struct AccountForm: View {
|
||||
isValidating: $isValidating,
|
||||
error: $validationError
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var footer: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
|
||||
Button("Save", action: submitForm)
|
||||
|
@ -9,26 +9,39 @@ struct AccountValidationStatus: View {
|
||||
@Binding var error: String?
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 4) {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Image(systemName: validationStatusSystemImage)
|
||||
.foregroundColor(validationStatusColor)
|
||||
|
||||
.frame(minWidth: 35, minHeight: 35)
|
||||
.imageScale(.medium)
|
||||
.opacity(isValidating ? 1 : (isValidated ? 1 : 0))
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
Text(isValid ? "Connected successfully (\(app?.name ?? "Unknown"))" : "Connection failed")
|
||||
if let error, !isValid {
|
||||
Text(error)
|
||||
.font(.caption2)
|
||||
.opacity(isValidated && !isValidating ? 1 : 0)
|
||||
}
|
||||
if errorVisible {
|
||||
Text(error ?? "")
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.lineLimit(nil)
|
||||
.multilineTextAlignment(.leading)
|
||||
.font(.footnote)
|
||||
.foregroundColor(.secondary)
|
||||
.truncationMode(.tail)
|
||||
.lineLimit(1)
|
||||
.padding(.top, 5)
|
||||
.opacity(errorTextVisible ? 1 : 0)
|
||||
}
|
||||
}
|
||||
.frame(minHeight: 35)
|
||||
.opacity(isValidating ? 0 : (isValidated ? 1 : 0))
|
||||
}
|
||||
|
||||
var errorVisible: Bool {
|
||||
#if !os(iOS)
|
||||
true
|
||||
#else
|
||||
errorTextVisible
|
||||
#endif
|
||||
}
|
||||
|
||||
var errorTextVisible: Bool {
|
||||
error != nil && isValidated && !isValid && !isValidating
|
||||
}
|
||||
|
||||
var validationStatusSystemImage: String {
|
||||
|
@ -22,9 +22,14 @@ struct InstanceForm: View {
|
||||
VStack(alignment: .leading) {
|
||||
Group {
|
||||
header
|
||||
|
||||
form
|
||||
|
||||
#if os(macOS)
|
||||
VStack {
|
||||
validationStatus
|
||||
}
|
||||
.frame(minHeight: 60, alignment: .topLeading)
|
||||
.padding(.horizontal, 15)
|
||||
#endif
|
||||
footer
|
||||
}
|
||||
.frame(maxWidth: 1000)
|
||||
@ -36,7 +41,8 @@ struct InstanceForm: View {
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
||||
.background(Color.background(scheme: colorScheme))
|
||||
#else
|
||||
.frame(width: 400, height: 150)
|
||||
.frame(width: 400, height: 180)
|
||||
.padding(.vertical)
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -80,11 +86,21 @@ struct InstanceForm: View {
|
||||
.autocapitalization(.none)
|
||||
.keyboardType(.URL)
|
||||
#endif
|
||||
|
||||
#if os(tvOS)
|
||||
VStack {
|
||||
validationStatus
|
||||
}
|
||||
.frame(minHeight: 100)
|
||||
#elseif os(iOS)
|
||||
validationStatus
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private var footer: some View {
|
||||
HStack {
|
||||
@ViewBuilder var validationStatus: some View {
|
||||
if !url.isEmpty {
|
||||
Section {
|
||||
AccountValidationStatus(
|
||||
app: $app,
|
||||
isValid: $isValid,
|
||||
@ -92,7 +108,12 @@ struct InstanceForm: View {
|
||||
isValidating: $isValidating,
|
||||
error: $validationError
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var footer: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
|
||||
Button("Save", action: submitForm)
|
||||
|
Loading…
Reference in New Issue
Block a user