metatext/Views/AddIdentityView.swift

59 lines
1.7 KiB
Swift
Raw Normal View History

// Copyright © 2020 Metabolist. All rights reserved.
import SwiftUI
2020-09-01 07:33:49 +00:00
import ViewModels
struct AddIdentityView: View {
@StateObject var viewModel: AddIdentityViewModel
2020-08-07 01:41:59 +00:00
@EnvironmentObject var rootViewModel: RootViewModel
var body: some View {
Form {
urlTextField
.autocapitalization(.none)
.disableAutocorrection(true)
.keyboardType(.URL)
Group {
if viewModel.loading {
ProgressView()
} else {
Button("add-identity.log-in",
action: viewModel.logInTapped)
2020-09-09 05:40:49 +00:00
Button("add-identity.browse-anonymously", action: viewModel.browseAnonymouslyTapped)
.frame(maxWidth: .infinity, alignment: .center)
}
}
.frame(maxWidth: .infinity, alignment: .center)
}
.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-09-09 12:05:43 +00:00
rootViewModel.identitySelected(id: id)
2020-08-07 01:41:59 +00:00
}
}
2020-09-07 04:56:18 +00:00
.onAppear(perform: viewModel.refreshFilter)
}
}
extension AddIdentityView {
private var urlTextField: some View {
TextField("add-identity.instance-url", text: $viewModel.urlFieldText)
}
}
2020-09-10 00:52:46 +00:00
extension AddIdentityError: LocalizedError {
public var errorDescription: String? {
NSLocalizedString("add-identity.unable-to-connect-to-instance", comment: "")
}
}
2020-07-31 21:40:57 +00:00
#if DEBUG
2020-09-01 07:33:49 +00:00
import PreviewViewModels
struct AddAccountView_Previews: PreviewProvider {
static var previews: some View {
2020-09-08 02:12:38 +00:00
AddIdentityView(viewModel: RootViewModel.preview.addIdentityViewModel())
}
}
2020-07-31 21:40:57 +00:00
#endif