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 KeychainStorage
|
||||||
import Profile
|
import Profile
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import UseCases
|
||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
|
|
||||||
@ -24,6 +25,10 @@ struct ContentView: View {
|
|||||||
@State private var user: User?
|
@State private var user: User?
|
||||||
@State private var showSheet: SheetView?
|
@State private var showSheet: SheetView?
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
private let getUser: GetUserUseCase = .init()
|
||||||
|
|
||||||
// MARK: Body
|
// MARK: Body
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@ -36,12 +41,6 @@ struct ContentView: View {
|
|||||||
showSheet = .profile
|
showSheet = .profile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
|
||||||
shouldShowLogin()
|
|
||||||
}
|
|
||||||
.onChange(of: account) { _ in
|
|
||||||
shouldShowLogin()
|
|
||||||
}
|
|
||||||
.sheet(item: $showSheet) { sheet in
|
.sheet(item: $showSheet) { sheet in
|
||||||
switch sheet {
|
switch sheet {
|
||||||
case .login:
|
case .login:
|
||||||
@ -56,6 +55,9 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.task(id: account) {
|
||||||
|
await loadUserOrLogin()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -63,10 +65,17 @@ struct ContentView: View {
|
|||||||
// MARK: - Helpers
|
// MARK: - Helpers
|
||||||
|
|
||||||
private extension ContentView {
|
private extension ContentView {
|
||||||
func shouldShowLogin() {
|
func loadUserOrLogin() async {
|
||||||
showSheet = account == nil
|
guard let account else {
|
||||||
? .login
|
showSheet = .login
|
||||||
: nil
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
showSheet = nil
|
||||||
|
user = try? await getUser(
|
||||||
|
username: account.username,
|
||||||
|
password: account.password
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user