Integrated the GetUserUseCase use case into the LoginView view.
This commit is contained in:
parent
27d2848a45
commit
332b8ab245
@ -7,10 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import APIService
|
import APIService
|
||||||
import DataModels
|
|
||||||
import DependencyInjection
|
|
||||||
import Dependencies
|
|
||||||
import KeychainStorage
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
public struct LoginView: View {
|
public struct LoginView: View {
|
||||||
@ -19,9 +15,15 @@ public struct LoginView: View {
|
|||||||
|
|
||||||
@State private var containerTopPadding: CGFloat = 0
|
@State private var containerTopPadding: CGFloat = 0
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
private let success: LoginSuccessClosure
|
||||||
|
|
||||||
// MARK: Initialisers
|
// MARK: Initialisers
|
||||||
|
|
||||||
public init() {}
|
public init(success: @escaping LoginSuccessClosure) {
|
||||||
|
self.success = success
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Body
|
// MARK: Body
|
||||||
|
|
||||||
@ -30,7 +32,7 @@ public struct LoginView: View {
|
|||||||
.vertical,
|
.vertical,
|
||||||
showsIndicators: false
|
showsIndicators: false
|
||||||
) {
|
) {
|
||||||
LoginContainer()
|
LoginContainer(success: success)
|
||||||
.padding(.horizontal, 24)
|
.padding(.horizontal, 24)
|
||||||
.padding(.top, containerTopPadding)
|
.padding(.top, containerTopPadding)
|
||||||
}
|
}
|
||||||
@ -39,6 +41,7 @@ public struct LoginView: View {
|
|||||||
.onPreferenceChange(ViewHeightPreferenceKey.self) { height in
|
.onPreferenceChange(ViewHeightPreferenceKey.self) { height in
|
||||||
containerTopPadding = height * 0.1
|
containerTopPadding = height * 0.1
|
||||||
}
|
}
|
||||||
|
.interactiveDismissDisabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -47,21 +50,23 @@ public struct LoginView: View {
|
|||||||
|
|
||||||
fileprivate extension LoginView {
|
fileprivate extension LoginView {
|
||||||
struct LoginContainer: View {
|
struct LoginContainer: View {
|
||||||
|
|
||||||
// MARK: Dependencies
|
|
||||||
|
|
||||||
@Dependency(\.apiService) private var apiService
|
|
||||||
|
|
||||||
// MARK: Storages
|
|
||||||
|
|
||||||
@KeychainStorage(key: .KeychainStorage.account) private var account: Account?
|
|
||||||
|
|
||||||
// MARK: States
|
// MARK: States
|
||||||
|
|
||||||
@State private var isAuthenticating: Bool = false
|
@State private var isAuthenticating: Bool = false
|
||||||
@State private var username: String = ""
|
@State private var username: String = ""
|
||||||
@State private var password: String = ""
|
@State private var password: String = ""
|
||||||
@State private var errorMessage: String?
|
@State private var errorMessage: String?
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
private let getUser: GetUserUseCase
|
||||||
|
|
||||||
|
// MARK: Initialisers
|
||||||
|
|
||||||
|
init(success: @escaping LoginSuccessClosure) {
|
||||||
|
self.getUser = .init(success: success)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Body
|
// MARK: Body
|
||||||
|
|
||||||
@ -133,12 +138,7 @@ private extension LoginView.LoginContainer {
|
|||||||
guard isAuthenticating else { return }
|
guard isAuthenticating else { return }
|
||||||
|
|
||||||
do {
|
do {
|
||||||
_ = try await apiService.getUser(credentials: .init(
|
try await getUser(
|
||||||
username: username,
|
|
||||||
password: password
|
|
||||||
))
|
|
||||||
|
|
||||||
account = .init(
|
|
||||||
username: username,
|
username: username,
|
||||||
password: password
|
password: password
|
||||||
)
|
)
|
||||||
@ -157,6 +157,6 @@ private extension LoginView.LoginContainer {
|
|||||||
|
|
||||||
struct LoginView_Previews: PreviewProvider {
|
struct LoginView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
LoginView()
|
LoginView { _, _ in }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user