Files
WerkoutIOS/Werkout_ios/Views/Login/LoginView.swift
Trey t f40c40c9bb WIP
2023-06-25 22:00:59 -05:00

74 lines
2.1 KiB
Swift

//
// LoginView.swift
// Werkout_ios
//
// Created by Trey Tartt on 6/25/23.
//
import SwiftUI
struct LoginView: View {
@State var email: String = ""
@State var password: String = ""
@Environment(\.dismiss) var dismiss
let completion: (() -> Void)
var body: some View {
VStack {
Text("Login")
.font(.title)
TextField("Email", text: $email)
.autocapitalization(.none)
.frame(height: 55)
.textFieldStyle(PlainTextFieldStyle())
.padding([.horizontal], 4)
.overlay(RoundedRectangle(cornerRadius: 16).stroke(Color(uiColor: .clear))).background(Color(uiColor: .init(red: 200/255, green: 200/255, blue: 200/255, alpha: 0.2)))
.cornerRadius(8)
TextField("Password", text: $password)
.autocapitalization(.none)
.frame(height: 55)
.textFieldStyle(PlainTextFieldStyle())
.padding([.horizontal], 4)
.overlay(RoundedRectangle(cornerRadius: 16).stroke(Color(uiColor: .clear))).background(Color(uiColor: .init(red: 200/255, green: 200/255, blue: 200/255, alpha: 0.2)))
.cornerRadius(8)
Button("Login", action: {
login()
})
.frame(maxWidth: .infinity, alignment: .center)
.frame(height: 44)
.foregroundColor(.blue)
.background(.yellow)
.cornerRadius(8)
.padding()
.frame(maxWidth: .infinity)
Spacer()
}
.padding()
}
func login() {
let postData = [
"email": email,
"password": password
]
UserStore.shared.login(postData: postData, completion: { success in
if success {
completion()
dismiss()
}
})
}
}
struct LoginView_Previews: PreviewProvider {
static var previews: some View {
LoginView(completion: {
})
}
}