2020-07-08 09:08:27 +02:00
|
|
|
//
|
2020-07-21 17:13:43 +02:00
|
|
|
// SettingsCredentialsAccountView.swift
|
2020-07-08 09:08:27 +02:00
|
|
|
// Multiplatform iOS
|
|
|
|
//
|
2020-07-21 17:13:43 +02:00
|
|
|
// Created by Rizwan on 21/07/20.
|
2020-07-08 09:08:27 +02:00
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import Account
|
|
|
|
|
2020-07-21 17:13:43 +02:00
|
|
|
struct SettingsCredentialsAccountView: View {
|
2020-07-08 09:08:27 +02:00
|
|
|
@Environment(\.presentationMode) var presentationMode
|
2020-07-21 17:13:43 +02:00
|
|
|
@ObservedObject var settingsModel: SettingsCredentialsAccountModel
|
2020-07-09 12:44:53 +02:00
|
|
|
|
2020-07-21 17:13:43 +02:00
|
|
|
init(account: Account) {
|
|
|
|
self.settingsModel = SettingsCredentialsAccountModel(account: account)
|
|
|
|
}
|
|
|
|
|
|
|
|
init(accountType: AccountType) {
|
|
|
|
self.settingsModel = SettingsCredentialsAccountModel(accountType: accountType)
|
2020-07-09 12:44:53 +02:00
|
|
|
}
|
2020-07-08 09:08:27 +02:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
NavigationView {
|
2020-07-08 12:39:49 +02:00
|
|
|
List {
|
2020-07-21 17:13:43 +02:00
|
|
|
Section(header: AccountHeaderImageView(image: AppAssets.image(for: settingsModel.accountType)!)) {
|
|
|
|
TextField(settingsModel.emailText, text: $settingsModel.email).textContentType(.emailAddress)
|
2020-07-13 17:22:05 +02:00
|
|
|
HStack {
|
|
|
|
if settingsModel.showPassword {
|
|
|
|
TextField("Password", text:$settingsModel.password)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SecureField("Password", text: $settingsModel.password)
|
|
|
|
}
|
|
|
|
Button(action: {
|
|
|
|
settingsModel.showPassword.toggle()
|
|
|
|
}) {
|
|
|
|
Text(settingsModel.showPassword ? "Hide" : "Show")
|
|
|
|
}
|
|
|
|
}
|
2020-07-21 19:40:18 +02:00
|
|
|
if settingsModel.apiUrlEnabled {
|
|
|
|
TextField("API URL", text: $settingsModel.apiUrl)
|
|
|
|
}
|
2020-07-08 12:39:49 +02:00
|
|
|
}
|
|
|
|
Section(footer: errorFooter) {
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
Button(action: { settingsModel.addAccount() }) {
|
|
|
|
if settingsModel.isUpdate {
|
|
|
|
Text("Update Account")
|
|
|
|
} else {
|
|
|
|
Text("Add Account")
|
2020-07-08 09:08:27 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-08 12:39:49 +02:00
|
|
|
.disabled(!settingsModel.isValid)
|
|
|
|
Spacer()
|
|
|
|
if settingsModel.busy {
|
|
|
|
ProgressView()
|
|
|
|
}
|
2020-07-08 09:08:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-08 12:39:49 +02:00
|
|
|
.listStyle(InsetGroupedListStyle())
|
|
|
|
.disabled(settingsModel.busy)
|
2020-07-08 09:08:27 +02:00
|
|
|
.onReceive(settingsModel.$shouldDismiss, perform: { dismiss in
|
|
|
|
if dismiss == true {
|
|
|
|
presentationMode.wrappedValue.dismiss()
|
|
|
|
}
|
|
|
|
})
|
2020-07-21 17:13:43 +02:00
|
|
|
.navigationBarTitle(Text(verbatim: settingsModel.accountName), displayMode: .inline)
|
2020-07-08 09:08:27 +02:00
|
|
|
.navigationBarItems(leading:
|
|
|
|
Button(action: { self.dismiss() }) { Text("Cancel") }
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var errorFooter: some View {
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
if settingsModel.showError {
|
2020-07-21 17:13:43 +02:00
|
|
|
Text(verbatim: settingsModel.accountCredentialsError!.description).foregroundColor(.red)
|
2020-07-08 09:08:27 +02:00
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func dismiss() {
|
|
|
|
presentationMode.wrappedValue.dismiss()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 17:13:43 +02:00
|
|
|
struct SettingsCredentialsAccountView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
SettingsCredentialsAccountView(accountType: .feedbin)
|
|
|
|
}
|
2020-07-08 09:08:27 +02:00
|
|
|
}
|