Move Account-related error handling up the hierarchy

This commit is contained in:
Angelo Stavrow 2022-05-08 09:16:46 -04:00
parent 11200a01a0
commit 01ba57ae75
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
3 changed files with 13 additions and 10 deletions

View File

@ -88,16 +88,6 @@ struct AccountLoginView: View {
.padding() .padding()
} }
} }
.onChange(of: model.hasError) { value in
if value {
if let error = model.currentError {
self.errorHandling.handle(error: error)
} else {
self.errorHandling.handle(error: AppError.genericError)
}
model.hasError = false
}
}
} }
} }

View File

@ -2,6 +2,7 @@ import SwiftUI
struct AccountView: View { struct AccountView: View {
@EnvironmentObject var model: WriteFreelyModel @EnvironmentObject var model: WriteFreelyModel
@EnvironmentObject var errorHandling: ErrorHandling
var body: some View { var body: some View {
if model.account.isLoggedIn { if model.account.isLoggedIn {
@ -16,6 +17,17 @@ struct AccountView: View {
.withErrorHandling() .withErrorHandling()
.padding(.top) .padding(.top)
} }
EmptyView()
.onChange(of: model.hasError) { value in
if value {
if let error = model.currentError {
self.errorHandling.handle(error: error)
} else {
self.errorHandling.handle(error: AppError.genericError)
}
model.hasError = false
}
}
} }
} }

View File

@ -9,6 +9,7 @@ struct SettingsView: View {
Form { Form {
Section(header: Text("Login Details")) { Section(header: Text("Login Details")) {
AccountView() AccountView()
.withErrorHandling()
} }
Section(header: Text("Appearance")) { Section(header: Text("Appearance")) {
PreferencesView(preferences: model.preferences) PreferencesView(preferences: model.preferences)