1
0
mirror of https://github.com/metabolist/metatext synced 2024-12-11 08:55:54 +01:00
metatext-app-ios-iphone-ipad/Views/AddIdentityView.swift

99 lines
3.8 KiB
Swift
Raw Normal View History

// Copyright © 2020 Metabolist. All rights reserved.
2020-09-10 11:38:21 +02:00
import KingfisherSwiftUI
import SwiftUI
2020-09-01 09:33:49 +02:00
import ViewModels
struct AddIdentityView: View {
@StateObject var viewModel: AddIdentityViewModel
2020-09-12 09:36:59 +02:00
@Environment(\.accessibilityReduceMotion) var accessibilityReduceMotion
2020-08-07 03:41:59 +02:00
@EnvironmentObject var rootViewModel: RootViewModel
2020-09-12 09:36:59 +02:00
2020-09-11 11:55:06 +02:00
@State private var navigateToRegister = false
var body: some View {
Form {
2020-09-10 11:38:21 +02:00
Section {
TextField("add-identity.instance-url", text: $viewModel.urlFieldText)
2020-09-12 09:36:59 +02:00
.textContentType(.URL)
2020-09-10 11:38:21 +02:00
.autocapitalization(.none)
.disableAutocorrection(true)
.keyboardType(.URL)
2020-09-12 21:09:54 +02:00
if let instance = viewModel.instance {
2020-09-10 11:38:21 +02:00
VStack(alignment: .center) {
2020-09-11 02:57:22 +02:00
KFImage(instance.thumbnail)
.placeholder {
ProgressView()
}
.resizable()
.aspectRatio(16 / 9, contentMode: .fill)
2020-09-11 03:59:43 +02:00
.background(Color.blue)
Spacer()
2020-09-10 11:38:21 +02:00
Text(instance.title)
.font(.headline)
Text(instance.uri)
.font(.subheadline)
.foregroundColor(.secondary)
2020-09-11 03:59:43 +02:00
Spacer()
2020-09-10 11:38:21 +02:00
}
.frame(maxWidth: .infinity, alignment: .center)
.listRowInsets(EdgeInsets())
}
2020-09-11 03:59:43 +02:00
Group {
if viewModel.loading {
ProgressView()
} else {
Button("add-identity.log-in",
action: viewModel.logInTapped)
2020-09-12 21:09:54 +02:00
if let instance = viewModel.instance, let url = viewModel.url,
2020-09-11 11:55:06 +02:00
instance.registrations {
ZStack {
NavigationLink(
destination: RegistrationView(
viewModel: viewModel.registrationViewModel(
instance: instance,
url: url)),
isActive: $navigateToRegister) {
EmptyView()
}
.hidden()
Button(instance.approvalRequired
? "add-identity.request-invite"
: "add-identity.join") {
navigateToRegister.toggle()
}
}
}
2020-09-11 03:59:43 +02:00
if viewModel.isPublicTimelineAvailable {
Button("add-identity.browse", action: viewModel.browseTapped)
}
}
}
.frame(maxWidth: .infinity, alignment: .center)
}
}
2020-09-12 09:36:59 +02:00
.animation(.default, if: !accessibilityReduceMotion)
.alertItem($viewModel.alertItem)
2020-09-07 06:56:18 +02:00
.onAppear(perform: viewModel.refreshFilter)
}
}
2020-09-10 02:52:46 +02:00
extension AddIdentityError: LocalizedError {
public var errorDescription: String? {
NSLocalizedString("add-identity.unable-to-connect-to-instance", comment: "")
}
}
2020-07-31 23:40:57 +02:00
#if DEBUG
2020-09-01 09:33:49 +02:00
import PreviewViewModels
struct AddAccountView_Previews: PreviewProvider {
static var previews: some View {
2020-09-11 11:55:06 +02:00
NavigationView {
AddIdentityView(viewModel: RootViewModel.preview.addIdentityViewModel())
.navigationBarTitleDisplayMode(.inline)
}
}
}
2020-07-31 23:40:57 +02:00
#endif