Port Feedbin credential update too SwfitUI.
This commit is contained in:
parent
83be0e5d97
commit
8dcf4966fb
|
@ -9,10 +9,12 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import Combine
|
import Combine
|
||||||
import Account
|
import Account
|
||||||
|
import RSWeb
|
||||||
|
|
||||||
struct SettingsDetailAccountView : View {
|
struct SettingsDetailAccountView : View {
|
||||||
@ObjectBinding var viewModel: ViewModel
|
@ObjectBinding var viewModel: ViewModel
|
||||||
@State private var verifyDelete = false
|
@State private var verifyDelete = false
|
||||||
|
@State private var showFeedbinCredentials = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
|
@ -26,15 +28,19 @@ struct SettingsDetailAccountView : View {
|
||||||
Text("Active")
|
Text("Active")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Section {
|
if viewModel.isCreditialsAvailable {
|
||||||
HStack {
|
Section {
|
||||||
Spacer()
|
HStack {
|
||||||
Button(action: {
|
Spacer()
|
||||||
|
Button(action: {
|
||||||
}) {
|
self.showFeedbinCredentials = true
|
||||||
Text("Credentials")
|
}) {
|
||||||
|
Text("Credentials")
|
||||||
|
}
|
||||||
|
.presentation(showFeedbinCredentials ? feedbinCredentialsModal : nil)
|
||||||
|
.onDisappear() { self.showFeedbinCredentials = false }
|
||||||
|
Spacer()
|
||||||
}
|
}
|
||||||
Spacer()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if viewModel.isDeletable {
|
if viewModel.isDeletable {
|
||||||
|
@ -62,6 +68,11 @@ struct SettingsDetailAccountView : View {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var feedbinCredentialsModal: Modal {
|
||||||
|
let feedbinViewModel = SettingsFeedbinAccountView.ViewModel(account: viewModel.account)
|
||||||
|
return Modal(SettingsFeedbinAccountView(viewModel: feedbinViewModel))
|
||||||
|
}
|
||||||
|
|
||||||
class ViewModel: BindableObject {
|
class ViewModel: BindableObject {
|
||||||
let didChange = PassthroughSubject<ViewModel, Never>()
|
let didChange = PassthroughSubject<ViewModel, Never>()
|
||||||
let account: Account
|
let account: Account
|
||||||
|
@ -94,6 +105,10 @@ struct SettingsDetailAccountView : View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isCreditialsAvailable: Bool {
|
||||||
|
return account.type != .onMyMac
|
||||||
|
}
|
||||||
|
|
||||||
var isDeletable: Bool {
|
var isDeletable: Bool {
|
||||||
return AccountManager.shared.defaultAccount != account
|
return AccountManager.shared.defaultAccount != account
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,7 @@ struct SettingsFeedbinAccountView : View {
|
||||||
@ObjectBinding var viewModel: ViewModel
|
@ObjectBinding var viewModel: ViewModel
|
||||||
@State var busy: Bool = false
|
@State var busy: Bool = false
|
||||||
@State var error: Text = Text("")
|
@State var error: Text = Text("")
|
||||||
var account: Account? = nil
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
List {
|
List {
|
||||||
|
@ -25,15 +24,15 @@ struct SettingsFeedbinAccountView : View {
|
||||||
SettingsAccountLabelView(accountImage: "accountFeedbin", accountLabel: "Feedbin").padding()
|
SettingsAccountLabelView(accountImage: "accountFeedbin", accountLabel: "Feedbin").padding()
|
||||||
) {
|
) {
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Text("Email:")
|
||||||
TextField($viewModel.email, placeholder: Text("Email"))
|
Divider()
|
||||||
.textContentType(.username)
|
TextField($viewModel.email)
|
||||||
Spacer()
|
.textContentType(.username)
|
||||||
}
|
}
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Text("Password:")
|
||||||
SecureField($viewModel.password, placeholder: Text("Password"))
|
Divider()
|
||||||
Spacer()
|
SecureField($viewModel.password)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Section(footer:
|
Section(footer:
|
||||||
|
@ -46,7 +45,11 @@ struct SettingsFeedbinAccountView : View {
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
Button(action: { self.addAccount() }) {
|
Button(action: { self.addAccount() }) {
|
||||||
Text("Add Account")
|
if viewModel.isUpdate {
|
||||||
|
Text("Update Account")
|
||||||
|
} else {
|
||||||
|
Text("Add Account")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.disabled(!viewModel.isValid)
|
.disabled(!viewModel.isValid)
|
||||||
Spacer()
|
Spacer()
|
||||||
|
@ -65,7 +68,8 @@ struct SettingsFeedbinAccountView : View {
|
||||||
private func addAccount() {
|
private func addAccount() {
|
||||||
|
|
||||||
busy = true
|
busy = true
|
||||||
|
error = Text("")
|
||||||
|
|
||||||
let emailAddress = viewModel.email.trimmingCharacters(in: .whitespaces)
|
let emailAddress = viewModel.email.trimmingCharacters(in: .whitespaces)
|
||||||
let credentials = Credentials.basic(username: emailAddress, password: viewModel.password)
|
let credentials = Credentials.basic(username: emailAddress, password: viewModel.password)
|
||||||
|
|
||||||
|
@ -80,11 +84,11 @@ struct SettingsFeedbinAccountView : View {
|
||||||
|
|
||||||
var newAccount = false
|
var newAccount = false
|
||||||
let workAccount: Account
|
let workAccount: Account
|
||||||
if self.account == nil {
|
if self.viewModel.account == nil {
|
||||||
workAccount = AccountManager.shared.createAccount(type: .feedbin)
|
workAccount = AccountManager.shared.createAccount(type: .feedbin)
|
||||||
newAccount = true
|
newAccount = true
|
||||||
} else {
|
} else {
|
||||||
workAccount = self.account!
|
workAccount = self.viewModel.account!
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -122,6 +126,18 @@ struct SettingsFeedbinAccountView : View {
|
||||||
|
|
||||||
class ViewModel: BindableObject {
|
class ViewModel: BindableObject {
|
||||||
let didChange = PassthroughSubject<ViewModel, Never>()
|
let didChange = PassthroughSubject<ViewModel, Never>()
|
||||||
|
var account: Account? = nil
|
||||||
|
|
||||||
|
init() {
|
||||||
|
}
|
||||||
|
|
||||||
|
init(account: Account) {
|
||||||
|
self.account = account
|
||||||
|
if case .basic(let username, let password) = try? account.retrieveBasicCredentials() {
|
||||||
|
self.email = username
|
||||||
|
self.password = password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var email: String = "" {
|
var email: String = "" {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -134,6 +150,10 @@ struct SettingsFeedbinAccountView : View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isUpdate: Bool {
|
||||||
|
return account != nil
|
||||||
|
}
|
||||||
|
|
||||||
var isValid: Bool {
|
var isValid: Bool {
|
||||||
return !email.isEmpty && !password.isEmpty
|
return !email.isEmpty && !password.isEmpty
|
||||||
}
|
}
|
||||||
|
@ -144,7 +164,7 @@ struct SettingsFeedbinAccountView : View {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
struct SettingsFeedbinAccountView_Previews : PreviewProvider {
|
struct SettingsFeedbinAccountView_Previews : PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
SettingsFeedbinAccountView(viewModel: SettingsFeedbinAccountView.ViewModel())
|
SettingsFeedbinAccountView(viewModel: SettingsFeedbinAccountView.ViewModel())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue