NetNewsWire/Multiplatform/Shared/Add/Add Account Sheets/AddFeedbinAccountView.swift

215 lines
5.1 KiB
Swift
Raw Normal View History

2020-12-05 02:53:10 +01:00
//
// AddFeedbinAccountView.swift
// Multiplatform macOS
//
// Created by Stuart Breckenridge on 02/12/2020.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account
import RSCore
import RSWeb
import Secrets
struct AddFeedbinAccountView: View {
@Environment (\.presentationMode) var presentationMode
@StateObject private var model = AddFeedbinViewModel()
var body: some View {
2020-12-05 15:18:10 +01:00
#if os(macOS)
macBody
#else
2020-12-05 15:58:11 +01:00
NavigationView {
2020-12-05 15:18:10 +01:00
iosBody
2020-12-05 15:58:11 +01:00
}
2020-12-05 15:18:10 +01:00
#endif
}
#if os(iOS)
var iosBody: some View {
List {
Section(header: formHeader, content: {
2020-12-05 15:58:11 +01:00
TextField("Email", text: $model.username)
if model.showPassword == false {
ZStack {
HStack {
SecureField("Password", text: $model.password)
Spacer()
Image(systemName: "eye.fill")
.foregroundColor(.accentColor)
.onTapGesture {
model.showPassword = true
}
}
}
}
else {
ZStack {
HStack {
TextField("Password", text: $model.password)
Spacer()
Image(systemName: "eye.slash.fill")
.foregroundColor(.accentColor)
.onTapGesture {
model.showPassword = false
}
}
}
}
2020-12-05 15:58:11 +01:00
})
Section(footer: formFooter, content: {
Button(action: {
model.authenticateFeedbin()
}, label: {
2020-12-07 12:52:35 +01:00
HStack {
Spacer()
Text("Add Account")
Spacer()
}
2020-12-05 15:58:11 +01:00
}).disabled(model.username.isEmpty || model.password.isEmpty)
2020-12-05 15:18:10 +01:00
})
2020-12-05 15:58:11 +01:00
}
.navigationBarItems(leading:
2020-12-05 15:18:10 +01:00
Button(action: {
presentationMode.wrappedValue.dismiss()
}, label: {
2020-12-07 12:22:35 +01:00
Text("Cancel")
2020-12-05 15:58:11 +01:00
}))
.listStyle(InsetGroupedListStyle())
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(Text("Feedbin"))
.alert(isPresented: $model.showError, content: {
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel(Text("Dismiss")))
})
.onReceive(model.$canDismiss, perform: { value in
if value == true {
presentationMode.wrappedValue.dismiss()
}
})
2020-12-05 15:18:10 +01:00
}
#endif
#if os(macOS)
var macBody: some View {
2020-12-05 02:53:10 +01:00
VStack {
HStack(spacing: 16) {
VStack(alignment: .leading) {
AccountType.feedbin.image()
.frame(width: 50, height: 50)
Spacer()
}
VStack(alignment: .leading, spacing: 8) {
Text("Sign in to your Feedbin account.")
.font(.headline)
HStack {
Text("Don't have a Feedbin account?")
.font(.callout)
Button(action: {
model.presentSignUpOption(.feedbin)
2020-12-05 02:53:10 +01:00
}, label: {
Text("Sign up here.").font(.callout)
}).buttonStyle(LinkButtonStyle())
}
HStack {
VStack(alignment: .trailing, spacing: 14) {
Text("Email")
Text("Password")
}
VStack(spacing: 8) {
TextField("me@email.com", text: $model.username)
SecureField("•••••••••••", text: $model.password)
}
}
Text("Your username and password will be encrypted and stored in Keychain.")
.foregroundColor(.secondary)
.font(.callout)
.lineLimit(2)
.padding(.top, 4)
Spacer()
HStack(spacing: 8) {
Spacer()
2020-12-05 09:13:43 +01:00
ProgressView()
.scaleEffect(CGSize(width: 0.5, height: 0.5))
.hidden(!model.isAuthenticating)
2020-12-05 02:53:10 +01:00
Button(action: {
presentationMode.wrappedValue.dismiss()
}, label: {
Text("Cancel")
.frame(width: 60)
}).keyboardShortcut(.cancelAction)
Button(action: {
2020-12-05 15:18:10 +01:00
model.authenticateFeedbin()
2020-12-05 02:53:10 +01:00
}, label: {
2020-12-05 14:09:34 +01:00
Text("Sign In")
2020-12-05 02:53:10 +01:00
.frame(width: 60)
})
.keyboardShortcut(.defaultAction)
.disabled(model.username.isEmpty || model.password.isEmpty)
}
}
}
}
.padding()
2020-12-05 14:09:34 +01:00
.frame(minWidth: 400, maxWidth: 400, minHeight: 230, maxHeight: 260)
2020-12-05 02:53:10 +01:00
.textFieldStyle(RoundedBorderTextFieldStyle())
.alert(isPresented: $model.showError, content: {
2020-12-05 14:09:34 +01:00
Alert(title: Text("Sign In Error"), message: Text(model.accountUpdateError.description), dismissButton: .cancel())
2020-12-05 09:13:43 +01:00
})
2020-12-05 15:18:10 +01:00
.onReceive(model.$canDismiss, perform: { value in
if value == true {
presentationMode.wrappedValue.dismiss()
}
})
}
#endif
2020-12-05 02:53:10 +01:00
2020-12-05 15:18:10 +01:00
var formHeader: some View {
HStack {
2020-12-05 15:58:11 +01:00
Spacer()
2020-12-05 15:18:10 +01:00
VStack(alignment: .center) {
AccountType.feedbin.image()
.resizable()
.frame(width: 50, height: 50)
2020-12-05 02:53:10 +01:00
}
2020-12-05 15:58:11 +01:00
Spacer()
}.padding(.vertical)
}
var formFooter: some View {
HStack {
Spacer()
VStack(spacing: 8) {
Text("Sign in to your Feedbin account and sync your subscriptions across your devices. Your username and password and password will be encrypted and stored in Keychain.").foregroundColor(.secondary)
Text("Don't have a Feedbin account?").foregroundColor(.secondary)
Button(action: {
model.presentSignUpOption(.feedbin)
}, label: {
2020-12-05 15:58:11 +01:00
Text("Sign Up Here").foregroundColor(.blue).multilineTextAlignment(.center)
})
ProgressView().hidden(!model.isAuthenticating)
2020-12-05 15:58:11 +01:00
}
.multilineTextAlignment(.center)
.font(.caption2)
Spacer()
}.padding(.vertical)
2020-12-05 02:53:10 +01:00
}
2020-12-05 15:18:10 +01:00
2020-12-05 02:53:10 +01:00
}
struct AddFeedbinAccountView_Previews: PreviewProvider {
static var previews: some View {
AddFeedbinAccountView()
}
}