Skip to content

Commit dc4bc9d

Browse files
committed
refactor: remove redundant ui code from phone auth related views
1 parent 45d5a3c commit dc4bc9d

2 files changed

Lines changed: 4 additions & 53 deletions

File tree

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/EnterPhoneNumberView.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ struct EnterPhoneNumberView: View {
2121
@Environment(AuthService.self) private var authService
2222
@State private var phoneNumber: String = ""
2323
@State private var selectedCountry: CountryData = .default
24-
@State private var currentError: AlertError? = nil
25-
@State private var isProcessing: Bool = false
2624

2725
var body: some View {
2826
VStack(spacing: 16) {
@@ -43,13 +41,12 @@ struct EnterPhoneNumberView: View {
4341
) {
4442
CountrySelector(
4543
selectedCountry: $selectedCountry,
46-
enabled: !isProcessing
44+
enabled: !(authService.authenticationState == .authenticating)
4745
)
4846
}
4947

5048
Button(action: {
5149
Task {
52-
isProcessing = true
5350
do {
5451
guard let provider = authService.currentPhoneProvider else {
5552
fatalError("No phone provider found")
@@ -60,14 +57,11 @@ struct EnterPhoneNumberView: View {
6057
verificationID: id,
6158
fullPhoneNumber: fullPhoneNumber
6259
))
63-
currentError = nil
6460
} catch {
65-
currentError = AlertError(message: error.localizedDescription)
6661
}
67-
isProcessing = false
6862
}
6963
}) {
70-
if isProcessing {
64+
if authService.authenticationState == .authenticating {
7165
ProgressView()
7266
.frame(height: 32)
7367
.frame(maxWidth: .infinity)
@@ -78,14 +72,14 @@ struct EnterPhoneNumberView: View {
7872
}
7973
}
8074
.buttonStyle(.borderedProminent)
81-
.disabled(isProcessing || phoneNumber.isEmpty)
75+
.disabled(authService.authenticationState == .authenticating || phoneNumber.isEmpty)
8276
.padding(.top, 8)
8377

8478
Spacer()
8579
}
8680
.navigationTitle(authService.string.phoneSignInTitle)
8781
.padding(.horizontal)
88-
.errorAlert(error: $currentError, okButtonLabel: authService.string.okButtonLabel)
82+
.errorAlert(error: authService.currentError, okButtonLabel: authService.string.okButtonLabel)
8983
}
9084
}
9185

firebase-debug.log

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)