2020-07-30 01:50:30 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import SwiftUI
|
2020-09-01 09:33:49 +02:00
|
|
|
import ViewModels
|
2020-07-30 01:50:30 +02:00
|
|
|
|
|
|
|
struct AddIdentityView: View {
|
|
|
|
@StateObject var viewModel: AddIdentityViewModel
|
2020-08-07 03:41:59 +02:00
|
|
|
@EnvironmentObject var rootViewModel: RootViewModel
|
2020-07-30 01:50:30 +02:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Form {
|
|
|
|
urlTextField
|
|
|
|
.autocapitalization(.none)
|
|
|
|
.disableAutocorrection(true)
|
|
|
|
.keyboardType(.URL)
|
|
|
|
Group {
|
|
|
|
if viewModel.loading {
|
|
|
|
ProgressView()
|
|
|
|
} else {
|
2020-08-09 13:27:38 +02:00
|
|
|
Button("add-identity.log-in",
|
|
|
|
action: viewModel.logInTapped)
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
2020-08-09 13:27:38 +02:00
|
|
|
Button("add-identity.browse-anonymously", action: viewModel.browseAnonymouslyTapped)
|
|
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|
|
|
|
.alertItem($viewModel.alertItem)
|
2020-08-14 03:24:53 +02:00
|
|
|
.onReceive(viewModel.addedIdentityID) { id in
|
2020-08-07 03:41:59 +02:00
|
|
|
withAnimation {
|
2020-08-14 03:24:53 +02:00
|
|
|
rootViewModel.newIdentitySelected(id: id)
|
2020-08-07 03:41:59 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension AddIdentityView {
|
|
|
|
private var urlTextField: some View {
|
|
|
|
TextField("add-identity.instance-url", text: $viewModel.urlFieldText)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 23:40:57 +02:00
|
|
|
#if DEBUG
|
2020-09-01 09:33:49 +02:00
|
|
|
import PreviewViewModels
|
|
|
|
|
2020-07-30 01:50:30 +02:00
|
|
|
struct AddAccountView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2020-09-01 09:33:49 +02:00
|
|
|
AddIdentityView(viewModel: .mock())
|
2020-07-30 01:50:30 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-31 23:40:57 +02:00
|
|
|
#endif
|