2020-07-29 23:50:30 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AddIdentityView: View {
|
|
|
|
@StateObject var viewModel: AddIdentityViewModel
|
2020-08-07 01:41:59 +00:00
|
|
|
@EnvironmentObject var rootViewModel: RootViewModel
|
2020-07-29 23:50:30 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Form {
|
2020-08-03 15:20:51 +00:00
|
|
|
#if os(macOS)
|
2020-08-03 05:54:47 +00:00
|
|
|
Spacer()
|
2020-08-03 15:20:51 +00:00
|
|
|
urlTextField
|
|
|
|
#else
|
2020-07-29 23:50:30 +00:00
|
|
|
urlTextField
|
|
|
|
.autocapitalization(.none)
|
|
|
|
.disableAutocorrection(true)
|
|
|
|
.keyboardType(.URL)
|
|
|
|
#endif
|
|
|
|
Group {
|
|
|
|
if viewModel.loading {
|
|
|
|
ProgressView()
|
|
|
|
} else {
|
2020-08-09 11:27:38 +00:00
|
|
|
Button("add-identity.log-in",
|
|
|
|
action: viewModel.logInTapped)
|
2020-07-29 23:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
2020-08-09 11:27:38 +00:00
|
|
|
Button("add-identity.browse-anonymously", action: viewModel.browseAnonymouslyTapped)
|
|
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
2020-08-03 15:20:51 +00:00
|
|
|
#if os(macOS)
|
2020-08-03 05:54:47 +00:00
|
|
|
Spacer()
|
2020-08-03 15:20:51 +00:00
|
|
|
#endif
|
2020-07-29 23:50:30 +00:00
|
|
|
}
|
2020-08-03 15:20:51 +00:00
|
|
|
.paddingIfMac()
|
2020-07-29 23:50:30 +00:00
|
|
|
.alertItem($viewModel.alertItem)
|
2020-08-14 01:24:53 +00:00
|
|
|
.onReceive(viewModel.addedIdentityID) { id in
|
2020-08-07 01:41:59 +00:00
|
|
|
withAnimation {
|
2020-08-14 01:24:53 +00:00
|
|
|
rootViewModel.newIdentitySelected(id: id)
|
2020-08-07 01:41:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-29 23:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension AddIdentityView {
|
|
|
|
private var urlTextField: some View {
|
|
|
|
TextField("add-identity.instance-url", text: $viewModel.urlFieldText)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 15:20:51 +00:00
|
|
|
private extension View {
|
|
|
|
func paddingIfMac() -> some View {
|
|
|
|
#if os(macOS)
|
|
|
|
return padding()
|
|
|
|
#else
|
|
|
|
return self
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 21:40:57 +00:00
|
|
|
#if DEBUG
|
2020-07-29 23:50:30 +00:00
|
|
|
struct AddAccountView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2020-08-09 05:37:04 +00:00
|
|
|
AddIdentityView(viewModel: .development)
|
2020-07-29 23:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-31 21:40:57 +00:00
|
|
|
#endif
|