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 {
|
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
|
|
|
|
onSignInStateChenge(.mainView)
|
|
|
|
}
|
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-01 18:13:36 +01:00
|
|
|
SignInView { applicationViewMode in }
|
2022-12-31 16:31:05 +01:00
|
|
|
}
|
|
|
|
}
|