61 lines
1.9 KiB
Swift
61 lines
1.9 KiB
Swift
//
|
|
// AuthScreen.swift
|
|
// AutoCat
|
|
//
|
|
// Created by Selim Mustafaev on 05.04.2025.
|
|
// Copyright © 2025 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import AutoCatCore
|
|
|
|
struct AuthScreen: View {
|
|
|
|
@State var viewModel: AuthViewModel
|
|
|
|
init() {
|
|
|
|
let resolver = ServiceContainer.shared
|
|
self.viewModel = AuthViewModel(
|
|
apiService: resolver.resolve(ApiServiceProtocol.self),
|
|
storageService: resolver.resolve(StorageServiceProtocol.self),
|
|
settingsService: resolver.resolve(SettingsServiceProtocol.self)
|
|
)
|
|
}
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
VStack(spacing: 16) {
|
|
Group {
|
|
TextField("Email", text: $viewModel.email, prompt: Text("Email"))
|
|
.keyboardType(.emailAddress)
|
|
SecureField("Password", text: $viewModel.password, prompt: Text("Password"))
|
|
}
|
|
.disableAutocorrection(true)
|
|
.autocapitalization(.none)
|
|
.padding(8)
|
|
.background {
|
|
RoundedRectangle(cornerRadius: 8)
|
|
.fill(.background)
|
|
.stroke(.secondary)
|
|
}
|
|
|
|
Group {
|
|
ACButtonView(title: "Log In") {
|
|
Task { await viewModel.login() }
|
|
}
|
|
ACButtonView(title: "Sign up") {
|
|
Task { await viewModel.signup() }
|
|
}
|
|
}
|
|
.disabled(!viewModel.actionsEnabled)
|
|
.opacity(viewModel.actionsEnabled ? 1 : 0.5)
|
|
}
|
|
.padding(.horizontal, 32)
|
|
}
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.hud($viewModel.hud)
|
|
.onAppear(perform: viewModel.onAppear)
|
|
}
|
|
}
|