Fixed the progress indicator in the login button of the LoginView view for the Login module.
This commit is contained in:
parent
011401a855
commit
76814cfe8b
@ -73,8 +73,7 @@ fileprivate extension LoginView {
|
||||
VStack(spacing: 32) {
|
||||
Text(
|
||||
"login.title.text",
|
||||
bundle: .module,
|
||||
comment: "Login view title text."
|
||||
bundle: .module
|
||||
)
|
||||
.font(.largeTitle)
|
||||
.fontWeight(.bold)
|
||||
@ -94,13 +93,13 @@ fileprivate extension LoginView {
|
||||
Label {
|
||||
Text(
|
||||
"login.button.log_in.text",
|
||||
bundle: .module,
|
||||
comment: "Log in button text."
|
||||
bundle: .module
|
||||
)
|
||||
.fontWeight(.semibold)
|
||||
} icon: {
|
||||
if isAuthenticating {
|
||||
ProgressView()
|
||||
.tint(.white)
|
||||
.controlSize(.regular)
|
||||
} else {
|
||||
EmptyView()
|
||||
@ -128,7 +127,9 @@ private extension LoginView.LoginContainer {
|
||||
// MARK: Computed
|
||||
|
||||
var isLoginDisabled: Bool {
|
||||
username.isEmpty || password.isEmpty
|
||||
username.isEmpty
|
||||
|| password.isEmpty
|
||||
|| errorMessage != nil
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
@ -136,23 +137,28 @@ private extension LoginView.LoginContainer {
|
||||
func authenticate() async {
|
||||
guard isAuthenticating else { return }
|
||||
|
||||
defer { isAuthenticating = false }
|
||||
|
||||
do {
|
||||
let user = try await getUser(
|
||||
username: username,
|
||||
password: password
|
||||
)
|
||||
|
||||
// Added some throttle (1 second) not to hide the loading indicator right away.
|
||||
try await Task.sleep(nanoseconds: .Constants.secondInNanoseconds)
|
||||
|
||||
authenticated(
|
||||
.init(
|
||||
username: username,
|
||||
password: password
|
||||
),
|
||||
try await getUser(
|
||||
username: username,
|
||||
password: password
|
||||
)
|
||||
user
|
||||
)
|
||||
} catch APIClientError.authenticationFailed {
|
||||
errorMessage = "login.error.authentication_failed.text"
|
||||
isAuthenticating = false
|
||||
} catch {
|
||||
errorMessage = "login.error.authentication_unknown.text"
|
||||
isAuthenticating = false
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,6 +168,14 @@ private extension LoginView.LoginContainer {
|
||||
|
||||
public typealias AuthenticatedClosure = (Account, User) -> Void
|
||||
|
||||
// MARK: - UInt64+Constants
|
||||
|
||||
private extension UInt64 {
|
||||
enum Constants {
|
||||
static let secondInNanoseconds = UInt64(1 * Double(NSEC_PER_SEC))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct LoginView_Previews: PreviewProvider {
|
||||
|
Loading…
x
Reference in New Issue
Block a user