Integrated the GetUserUseCase use case into the ContentView view for the BeReal app target.
This commit is contained in:
parent
07ffd2bf80
commit
c1c25c356d
@ -12,6 +12,7 @@ import Login
|
||||
import KeychainStorage
|
||||
import Profile
|
||||
import SwiftUI
|
||||
import UseCases
|
||||
|
||||
struct ContentView: View {
|
||||
|
||||
@ -24,6 +25,10 @@ struct ContentView: View {
|
||||
@State private var user: User?
|
||||
@State private var showSheet: SheetView?
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let getUser: GetUserUseCase = .init()
|
||||
|
||||
// MARK: Body
|
||||
|
||||
var body: some View {
|
||||
@ -36,12 +41,6 @@ struct ContentView: View {
|
||||
showSheet = .profile
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
shouldShowLogin()
|
||||
}
|
||||
.onChange(of: account) { _ in
|
||||
shouldShowLogin()
|
||||
}
|
||||
.sheet(item: $showSheet) { sheet in
|
||||
switch sheet {
|
||||
case .login:
|
||||
@ -56,6 +55,9 @@ struct ContentView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.task(id: account) {
|
||||
await loadUserOrLogin()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -63,10 +65,17 @@ struct ContentView: View {
|
||||
// MARK: - Helpers
|
||||
|
||||
private extension ContentView {
|
||||
func shouldShowLogin() {
|
||||
showSheet = account == nil
|
||||
? .login
|
||||
: nil
|
||||
func loadUserOrLogin() async {
|
||||
guard let account else {
|
||||
showSheet = .login
|
||||
return
|
||||
}
|
||||
|
||||
showSheet = nil
|
||||
user = try? await getUser(
|
||||
username: account.username,
|
||||
password: account.password
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user