Impressia/Vernissage/Views/SignInView.swift

53 lines
1.5 KiB
Swift
Raw Normal View History

2022-12-31 16:31:05 +01:00
//
// https://mczachurski.dev
// Copyright © 2022 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import SwiftUI
struct SignInView: View {
@Environment(\.managedObjectContext) private var viewContext
@EnvironmentObject var applicationState: ApplicationState
@State private var serverAddress: String = ""
2023-01-08 15:43:55 +01:00
var onSignInStateChenge: ((_ applicationViewMode: ApplicationViewMode) -> Void)?
2022-12-31 16:31:05 +01:00
var body: some View {
VStack {
2023-01-05 11:55:20 +01:00
// TODO: Rebild signin.
2022-12-31 16:31:05 +01:00
HStack {
TextField(
"Server address",
text: $serverAddress
)
.onSubmit {
}
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
Button("Go") {
Task {
2023-01-03 14:09:22 +01:00
try await AuthorizationService.shared.signIn(serverAddress: serverAddress, { accountData in
2023-01-08 14:50:37 +01:00
DispatchQueue.main.async {
self.applicationState.accountData = accountData
2023-01-08 15:43:55 +01:00
onSignInStateChenge?(.mainView)
2023-01-08 14:50:37 +01:00
}
2023-01-03 14:09:22 +01:00
})
2022-12-31 16:31:05 +01:00
}
}
}
}
.padding()
.navigationBarTitle("Sign in to Pixelfed")
.navigationBarTitleDisplayMode(.inline)
}
}
struct SignInView_Previews: PreviewProvider {
static var previews: some View {
2023-01-08 15:43:55 +01:00
SignInView()
2022-12-31 16:31:05 +01:00
}
}