mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-03-25 08:55:46 +00:00
show auth errors inline on sign in view
This commit is contained in:
parent
499d33f8e0
commit
2289692422
3 changed files with 23 additions and 8 deletions
|
|
@ -127,6 +127,7 @@ class AppState: ObservableObject {
|
|||
}
|
||||
|
||||
func signIn(username: String, password: String) {
|
||||
authError = nil
|
||||
signIn(username: username, password: password)
|
||||
.sink(
|
||||
receiveCompletion: { _ in },
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ struct MainWindow: View {
|
|||
.padding()
|
||||
} else {
|
||||
SignInCredentialsView()
|
||||
.frame(width: 400)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,30 +14,42 @@ struct SignInCredentialsView: View {
|
|||
Text("Apple ID:")
|
||||
.frame(minWidth: 100, alignment: .trailing)
|
||||
TextField("example@icloud.com", text: $username)
|
||||
.frame(width: 250)
|
||||
}
|
||||
HStack {
|
||||
Text("Password:")
|
||||
.frame(minWidth: 100, alignment: .trailing)
|
||||
SecureField("Required", text: $password)
|
||||
.frame(width: 250)
|
||||
}
|
||||
if appState.authError != nil {
|
||||
HStack {
|
||||
Text("")
|
||||
.frame(minWidth: 100)
|
||||
Text(appState.authError?.legibleLocalizedDescription ?? "")
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.foregroundColor(.red)
|
||||
}
|
||||
}
|
||||
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Cancel") { appState.presentedSheet = nil }
|
||||
.keyboardShortcut(.cancelAction)
|
||||
ProgressButton(isInProgress: appState.isProcessingAuthRequest,
|
||||
action: { appState.signIn(username: username, password: password) }) {
|
||||
Text("Next")
|
||||
Button("Cancel") {
|
||||
appState.authError = nil
|
||||
appState.presentedSheet = nil
|
||||
}
|
||||
.keyboardShortcut(.cancelAction)
|
||||
ProgressButton(
|
||||
isInProgress: appState.isProcessingAuthRequest,
|
||||
action: { appState.signIn(username: username, password: password) },
|
||||
label: {
|
||||
Text("Next")
|
||||
}
|
||||
)
|
||||
.disabled(username.isEmpty || password.isEmpty)
|
||||
.keyboardShortcut(.defaultAction)
|
||||
}
|
||||
.frame(height: 25)
|
||||
}
|
||||
.padding()
|
||||
.emittingError($appState.authError, recoveryHandler: { _ in })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,5 +57,6 @@ struct SignInCredentialsView_Previews: PreviewProvider {
|
|||
static var previews: some View {
|
||||
SignInCredentialsView()
|
||||
.environmentObject(AppState())
|
||||
.previewLayout(.sizeThatFits)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue