Impressia/Vernissage/Views/SignInView.swift

50 lines
1.4 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 = ""
var onSignInStateChenge: (_ applicationViewMode: ApplicationViewMode) -> Void?
var body: some View {
VStack {
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
self.applicationState.accountData = accountData
onSignInStateChenge(.mainView)
})
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-01 18:13:36 +01:00
SignInView { applicationViewMode in }
2022-12-31 16:31:05 +01:00
}
}