NetNewsWire/Multiplatform/iOS/Settings/Accounts/SettingsCredentialsAccountV...

98 lines
2.5 KiB
Swift
Raw Normal View History

//
// SettingsCredentialsAccountView.swift
// Multiplatform iOS
//
// Created by Rizwan on 21/07/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account
struct SettingsCredentialsAccountView: View {
@Environment(\.presentationMode) var presentationMode
@ObservedObject var settingsModel: SettingsCredentialsAccountModel
init(account: Account) {
self.settingsModel = SettingsCredentialsAccountModel(account: account)
}
init(accountType: AccountType) {
self.settingsModel = SettingsCredentialsAccountModel(accountType: accountType)
}
var body: some View {
NavigationView {
2020-07-08 12:39:49 +02:00
List {
Section(header: AccountHeaderImageView(image: AppAssets.image(for: settingsModel.accountType)!)) {
TextField(settingsModel.emailText, text: $settingsModel.email).textContentType(.emailAddress)
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")
}
}
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 12:39:49 +02:00
.disabled(!settingsModel.isValid)
Spacer()
if settingsModel.busy {
ProgressView()
}
}
}
}
2020-07-08 12:39:49 +02:00
.listStyle(InsetGroupedListStyle())
.disabled(settingsModel.busy)
.onReceive(settingsModel.$shouldDismiss, perform: { dismiss in
if dismiss == true {
presentationMode.wrappedValue.dismiss()
}
})
.navigationBarTitle(Text(verbatim: settingsModel.accountName), displayMode: .inline)
.navigationBarItems(leading:
Button(action: { self.dismiss() }) { Text("Cancel") }
)
}
}
var errorFooter: some View {
HStack {
Spacer()
if settingsModel.showError {
Text(verbatim: settingsModel.accountCredentialsError!.description).foregroundColor(.red)
}
Spacer()
}
}
private func dismiss() {
presentationMode.wrappedValue.dismiss()
}
}
struct SettingsCredentialsAccountView_Previews: PreviewProvider {
static var previews: some View {
SettingsCredentialsAccountView(accountType: .feedbin)
}
}