From 332b8ab245755b78759b834fff97416aac3b4143 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Mon, 12 Dec 2022 00:55:37 +0100 Subject: [PATCH] Integrated the GetUserUseCase use case into the LoginView view. --- .../Sources/Login/UI/Views/LoginView.swift | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Modules/Sources/Login/UI/Views/LoginView.swift b/Modules/Sources/Login/UI/Views/LoginView.swift index 754fe4c..619229b 100644 --- a/Modules/Sources/Login/UI/Views/LoginView.swift +++ b/Modules/Sources/Login/UI/Views/LoginView.swift @@ -7,10 +7,6 @@ // import APIService -import DataModels -import DependencyInjection -import Dependencies -import KeychainStorage import SwiftUI public struct LoginView: View { @@ -19,9 +15,15 @@ public struct LoginView: View { @State private var containerTopPadding: CGFloat = 0 + // MARK: Properties + + private let success: LoginSuccessClosure + // MARK: Initialisers - public init() {} + public init(success: @escaping LoginSuccessClosure) { + self.success = success + } // MARK: Body @@ -30,7 +32,7 @@ public struct LoginView: View { .vertical, showsIndicators: false ) { - LoginContainer() + LoginContainer(success: success) .padding(.horizontal, 24) .padding(.top, containerTopPadding) } @@ -39,6 +41,7 @@ public struct LoginView: View { .onPreferenceChange(ViewHeightPreferenceKey.self) { height in containerTopPadding = height * 0.1 } + .interactiveDismissDisabled() } } @@ -47,21 +50,23 @@ public struct LoginView: View { fileprivate extension LoginView { struct LoginContainer: View { - - // MARK: Dependencies - - @Dependency(\.apiService) private var apiService - - // MARK: Storages - - @KeychainStorage(key: .KeychainStorage.account) private var account: Account? - + // MARK: States @State private var isAuthenticating: Bool = false @State private var username: String = "" @State private var password: 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 @@ -133,12 +138,7 @@ private extension LoginView.LoginContainer { guard isAuthenticating else { return } do { - _ = try await apiService.getUser(credentials: .init( - username: username, - password: password - )) - - account = .init( + try await getUser( username: username, password: password ) @@ -157,6 +157,6 @@ private extension LoginView.LoginContainer { struct LoginView_Previews: PreviewProvider { static var previews: some View { - LoginView() + LoginView { _, _ in } } }