mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-03-25 08:55:46 +00:00
Disable the action button when the AppState isProcessingRequest
This commit is contained in:
parent
1d9db94efa
commit
4e03c59d0a
6 changed files with 12 additions and 5 deletions
|
|
@ -164,9 +164,9 @@
|
|||
children = (
|
||||
CA735108257BF96D00EA9CF8 /* AttributedText.swift */,
|
||||
CA73510C257BFCEF00EA9CF8 /* NSAttributedString+.swift */,
|
||||
CA5D781D257365D6008EDE9D /* PinCodeTextView.swift */,
|
||||
CAA1CB34255A5AD5003FD669 /* SignInCredentialsView.swift */,
|
||||
CAA1CB44255A5B60003FD669 /* SignIn2FAView.swift */,
|
||||
CA5D781D257365D6008EDE9D /* PinCodeTextView.swift */,
|
||||
CAA1CB48255A5C97003FD669 /* SignInSMSView.swift */,
|
||||
CAA1CB4C255A5CFD003FD669 /* SignInPhoneListView.swift */,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class AppState: ObservableObject {
|
|||
@Published var allVersions: [XcodeVersion] = []
|
||||
@Published var error: AlertContent?
|
||||
@Published var presentingSignInAlert = false
|
||||
@Published var isProcessingRequest = false
|
||||
@Published var secondFactorData: SecondFactorData?
|
||||
|
||||
// MARK: - Authentication
|
||||
|
|
@ -62,11 +63,13 @@ class AppState: ObservableObject {
|
|||
try? Current.keychain.set(password, key: username)
|
||||
Current.defaults.set(username, forKey: "username")
|
||||
|
||||
isProcessingRequest = true
|
||||
return client.login(accountName: username, password: password)
|
||||
.receive(on: DispatchQueue.main)
|
||||
.handleEvents(
|
||||
receiveOutput: { authenticationState in
|
||||
self.authenticationState = authenticationState
|
||||
self.isProcessingRequest = false
|
||||
},
|
||||
receiveCompletion: { completion in
|
||||
self.handleAuthenticationFlowCompletion(completion)
|
||||
|
|
@ -85,10 +88,12 @@ class AppState: ObservableObject {
|
|||
}
|
||||
|
||||
func requestSMS(to trustedPhoneNumber: AuthOptionsResponse.TrustedPhoneNumber, authOptions: AuthOptionsResponse, sessionData: AppleSessionData) {
|
||||
isProcessingRequest = true
|
||||
client.requestSMSSecurityCode(to: trustedPhoneNumber, authOptions: authOptions, sessionData: sessionData)
|
||||
.sink(
|
||||
receiveCompletion: { completion in
|
||||
self.handleAuthenticationFlowCompletion(completion)
|
||||
self.isProcessingRequest = false
|
||||
},
|
||||
receiveValue: { authenticationState in
|
||||
self.authenticationState = authenticationState
|
||||
|
|
@ -105,11 +110,13 @@ class AppState: ObservableObject {
|
|||
}
|
||||
|
||||
func submitSecurityCode(_ code: SecurityCode, sessionData: AppleSessionData) {
|
||||
isProcessingRequest = true
|
||||
client.submitSecurityCode(code, sessionData: sessionData)
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink(
|
||||
receiveCompletion: { completion in
|
||||
self.handleAuthenticationFlowCompletion(completion)
|
||||
self.isProcessingRequest = false
|
||||
},
|
||||
receiveValue: { authenticationState in
|
||||
self.authenticationState = authenticationState
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ struct SignIn2FAView: View {
|
|||
Spacer()
|
||||
Button("Continue", action: { appState.submitSecurityCode(.device(code: code), sessionData: sessionData) })
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(code.count != authOptions.securityCode.length)
|
||||
.disabled(code.count != authOptions.securityCode.length || appState.isProcessingRequest)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ struct SignInCredentialsView: View {
|
|||
Button("Cancel") { isPresented = false }
|
||||
.keyboardShortcut(.cancelAction)
|
||||
Button("Next") { appState.signIn(username: username, password: password) }
|
||||
.disabled(username.isEmpty)
|
||||
.disabled(username.isEmpty || appState.isProcessingRequest)
|
||||
.keyboardShortcut(.defaultAction)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ struct SignInPhoneListView: View {
|
|||
Spacer()
|
||||
Button("Continue", action: { appState.requestSMS(to: authOptions.trustedPhoneNumbers!.first { $0.id == selectedPhoneNumberID }!, authOptions: authOptions, sessionData: sessionData) })
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(selectedPhoneNumberID == nil)
|
||||
.disabled(selectedPhoneNumberID == nil || appState.isProcessingRequest)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ struct SignInSMSView: View {
|
|||
Spacer()
|
||||
Button("Continue", action: { appState.submitSecurityCode(.sms(code: code, phoneNumberId: trustedPhoneNumber.id), sessionData: sessionData) })
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(code.count != authOptions.securityCode.length)
|
||||
.disabled(code.count != authOptions.securityCode.length || appState.isProcessingRequest)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
|
|
|
|||
Loading…
Reference in a new issue