Add account sheets are now showing

This commit is contained in:
Stuart Breckenridge
2020-12-04 09:15:37 +08:00
parent 0dac343748
commit 6bc0728fdb
5 changed files with 156 additions and 6 deletions

View File

@@ -10,12 +10,22 @@ import Foundation
import Account
import Combine
class AccountsPreferencesModel: ObservableObject {
public enum AccountConfigurationSheets: Equatable {
case addAccountPicker, addSelectedAccount(AccountType), credentials, none
enum AccountConfigurationSheets {
case addAccountPicker, credentials, none
public static func == (lhs: AccountConfigurationSheets, rhs: AccountConfigurationSheets) -> Bool {
switch (lhs, rhs) {
case (let .addSelectedAccount(lhsType), let .addSelectedAccount(rhsType)):
return lhsType == rhsType
default:
return false
}
}
}
public class AccountsPreferencesModel: ObservableObject {
// Selected Account
public private(set) var account: Account?
@@ -57,7 +67,7 @@ class AccountsPreferencesModel: ObservableObject {
@Published var showSheet: Bool = false
@Published var sheetToShow: AccountConfigurationSheets = .none {
didSet {
showSheet = sheetToShow != .none
if sheetToShow == .none { showSheet = false } else { showSheet = true }
}
}
@Published var showDeleteConfirmation: Bool = false

View File

@@ -30,11 +30,26 @@ struct AccountsPreferencesView: View {
content: {
switch viewModel.sheetToShow {
case .addAccountPicker:
AddAccountView()
AddAccountView(accountToAdd: $viewModel.sheetToShow)
case .credentials:
EditAccountCredentialsView(viewModel: viewModel)
case .none:
EmptyView()
case .addSelectedAccount(let type):
switch type {
case .onMyMac:
AddLocalAccountView()
case .feedbin:
AddFeedbinAccountView()
case .cloudKit:
AddCloudKitAccountView()
case .feedWrangler:
AddFeedWranglerAccountView()
case .newsBlur:
AddNewsBlurAccountView()
default:
AddReaderAPIAccountView(accountType: type)
}
}
})
.alert(isPresented: $viewModel.showDeleteConfirmation, content: {

View File

@@ -72,6 +72,7 @@ enum AddAccountSections: Int, CaseIterable {
struct AddAccountView: View {
@State private var selectedAccount: AccountType = .onMyMac
@Binding public var accountToAdd: AccountConfigurationSheets
@Environment(\.presentationMode) var presentationMode
var body: some View {
@@ -108,8 +109,10 @@ struct AddAccountView: View {
}
if #available(OSX 11.0, *) {
Button(action: {
//
presentationMode.wrappedValue.dismiss()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
accountToAdd = AccountConfigurationSheets.addSelectedAccount(selectedAccount)
})
}, label: {
Text("Continue")
.frame(width: 80)
@@ -120,6 +123,9 @@ struct AddAccountView: View {
} else {
Button(action: {
presentationMode.wrappedValue.dismiss()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
accountToAdd = AccountConfigurationSheets.addSelectedAccount(selectedAccount)
})
}, label: {
Text("Continue")
.frame(width: 80)

View File

@@ -0,0 +1,115 @@
//
// AddReaderAPIAccountView.swift
// Multiplatform macOS
//
// Created by Stuart Breckenridge on 03/12/2020.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account
struct AddReaderAPIAccountView: View {
@Environment (\.presentationMode) var presentationMode
@State private var username: String = ""
@State private var password: String = ""
public var accountType: AccountType
var body: some View {
VStack {
HStack(spacing: 16) {
VStack(alignment: .leading) {
accountType.image()
.resizable()
.frame(width: 50, height: 50)
Spacer()
}
VStack(alignment: .leading, spacing: 8) {
Text("Sign in to your \(accountType.localizedAccountName()) account.")
.font(.headline)
HStack {
if accountType == .freshRSS {
Text("Don't have a \(accountType.localizedAccountName()) instance?")
.font(.callout)
} else {
Text("Don't have an \(accountType.localizedAccountName()) account?")
.font(.callout)
}
Button(action: {
signUp()
}, label: {
Text(accountType == .freshRSS ? "Find out more." : "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: $username)
SecureField("•••••••••••", text: $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()
ProgressView().scaleEffect(CGSize(width: 0.5, height: 0.5))
Button(action: {
presentationMode.wrappedValue.dismiss()
}, label: {
Text("Cancel")
.frame(width: 60)
}).keyboardShortcut(.cancelAction)
Button(action: {
presentationMode.wrappedValue.dismiss()
}, label: {
Text("Create")
.frame(width: 60)
})
.keyboardShortcut(.defaultAction)
.disabled(username.isEmpty && password.isEmpty)
}
}
}
}
.padding()
.frame(width: 400, height: 230)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
private func signUp() {
switch accountType {
case .freshRSS:
NSWorkspace.shared.open(URL(string: "https://freshrss.org")!)
case .inoreader:
NSWorkspace.shared.open(URL(string: "https://www.inoreader.com")!)
case .bazQux:
NSWorkspace.shared.open(URL(string: "https://bazqux.com")!)
case .theOldReader:
NSWorkspace.shared.open(URL(string: "https://theoldreader.com")!)
default:
return
}
}
}
struct AddReaderAPIAccountView_Previews: PreviewProvider {
static var previews: some View {
AddReaderAPIAccountView(accountType: .freshRSS)
}
}