WiP on Edit Account

This commit is contained in:
Stuart Breckenridge 2020-07-14 10:44:59 +08:00
parent 15b980cabf
commit 39a71077b4
No known key found for this signature in database
GPG Key ID: 79BD673276AE83CE
4 changed files with 122 additions and 6 deletions

View File

@ -12,10 +12,32 @@ import Combine
class AccountsPreferencesModel: ObservableObject {
// Configured Accounts
@Published var sortedAccounts: [Account] = []
@Published var selectedConfiguredAccountID: String? = nil
@Published var selectedConfiguredAccountID: String? = AccountManager.shared.defaultAccount.accountID {
didSet {
if let accountID = selectedConfiguredAccountID {
account = sortedAccounts.first(where: { $0.accountID == accountID })
accountIsActive = account?.isActive ?? false
accountName = account?.name ?? ""
}
}
}
@Published var showAddAccountView: Bool = false
// Edit Account
public private(set) var account: Account?
@Published var accountIsActive: Bool = false {
didSet {
account?.isActive = accountIsActive
}
}
@Published var accountName: String = "" {
didSet {
account?.name = accountName
}
}
var selectedAccountIsDefault: Bool {
guard let selected = selectedConfiguredAccountID else {
return true
@ -39,6 +61,18 @@ class AccountsPreferencesModel: ObservableObject {
NotificationCenter.default.publisher(for: .UserDidDeleteAccount).sink(receiveValue: { _ in
self.selectedConfiguredAccountID = nil
self.sortedAccounts = AccountManager.shared.sortedAccounts
self.selectedConfiguredAccountID = AccountManager.shared.defaultAccount.accountID
}).store(in: &notificationSubscriptions)
NotificationCenter.default.publisher(for: .AccountStateDidChange).sink(receiveValue: { notification in
guard let account = notification.object as? Account else {
return
}
if account.accountID == self.account?.accountID {
self.account = account
self.accountIsActive = account.isActive
self.accountName = account.name ?? ""
}
}).store(in: &notificationSubscriptions)
}

View File

@ -27,12 +27,11 @@ struct AccountsPreferencesView: View {
bottomButtonStack
}, alignment: .bottom)
}
.frame(width: 225, height: 300, alignment: .leading)
.frame(width: 160, height: 300, alignment: .leading)
.border(Color.gray, width: 1)
VStack(alignment: .leading) {
EmptyView()
Spacer()
}.frame(width: 225, height: 300, alignment: .leading)
EditAccountView(viewModel: viewModel)
.frame(height: 300, alignment: .leading)
}
Spacer()
}.sheet(isPresented: $viewModel.showAddAccountView,

View File

@ -0,0 +1,79 @@
//
// EditAccountView.swift
// Multiplatform macOS
//
// Created by Stuart Breckenridge on 14/7/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account
import Combine
struct EditAccountView: View {
@ObservedObject var viewModel: AccountsPreferencesModel
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 8, style: .circular)
.foregroundColor(Color.secondary.opacity(0.1))
VStack {
HStack {
Spacer()
Button("Account Information", action: {})
Spacer()
}.padding(4)
if viewModel.account != nil {
Form(content: {
HStack(alignment: .top) {
Text("Type: ")
.frame(width: 50)
VStack(alignment: .leading) {
Text(viewModel.account!.defaultName)
Toggle("Active", isOn: $viewModel.accountIsActive)
}
}
HStack(alignment: .top) {
Text("Name: ")
.frame(width: 50)
VStack(alignment: .leading) {
TextField(viewModel.account!.name ?? "", text: $viewModel.accountName)
.textFieldStyle(RoundedBorderTextFieldStyle())
Text("The name appears in the sidebar. It can be anything you want. You can even use emoji. 🎸")
.foregroundColor(.secondary)
}
}
Spacer()
if viewModel.account?.type != .onMyMac {
HStack {
Spacer()
Button("Credentials", action: {
})
Spacer()
}
}
}).padding()
}
Spacer()
}
}
}
}
struct EditAccountView_Previews: PreviewProvider {
static var previews: some View {
EditAccountView(viewModel: AccountsPreferencesModel())
}
}

View File

@ -23,6 +23,7 @@
1769E32724BC5B6C000E1E8E /* AddAccountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1769E32624BC5B6C000E1E8E /* AddAccountModel.swift */; };
1769E32924BCAFC7000E1E8E /* AddAccountPickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1769E32824BCAFC7000E1E8E /* AddAccountPickerRow.swift */; };
1769E32B24BCB030000E1E8E /* ConfiguredAccountRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1769E32A24BCB030000E1E8E /* ConfiguredAccountRow.swift */; };
1769E32D24BD20A0000E1E8E /* EditAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1769E32C24BD20A0000E1E8E /* EditAccountView.swift */; };
1776E88E24AC5F8A00E78166 /* AppDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1776E88D24AC5F8A00E78166 /* AppDefaults.swift */; };
1776E88F24AC5F8A00E78166 /* AppDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1776E88D24AC5F8A00E78166 /* AppDefaults.swift */; };
17930ED424AF10EE00A9BA52 /* AddWebFeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17930ED324AF10EE00A9BA52 /* AddWebFeedView.swift */; };
@ -1798,6 +1799,7 @@
1769E32624BC5B6C000E1E8E /* AddAccountModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddAccountModel.swift; sourceTree = "<group>"; };
1769E32824BCAFC7000E1E8E /* AddAccountPickerRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddAccountPickerRow.swift; sourceTree = "<group>"; };
1769E32A24BCB030000E1E8E /* ConfiguredAccountRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfiguredAccountRow.swift; sourceTree = "<group>"; };
1769E32C24BD20A0000E1E8E /* EditAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditAccountView.swift; sourceTree = "<group>"; };
1776E88D24AC5F8A00E78166 /* AppDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDefaults.swift; sourceTree = "<group>"; };
17930ED324AF10EE00A9BA52 /* AddWebFeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWebFeedView.swift; sourceTree = "<group>"; };
179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsNewsBlurWindowController.swift; sourceTree = "<group>"; };
@ -2546,6 +2548,7 @@
1769E32124BC5925000E1E8E /* AccountsPreferencesModel.swift */,
1729529024AA1CAA00D65E66 /* AccountsPreferencesView.swift */,
1769E32A24BCB030000E1E8E /* ConfiguredAccountRow.swift */,
1769E32C24BD20A0000E1E8E /* EditAccountView.swift */,
1769E32324BC5A50000E1E8E /* Add Account */,
);
path = Accounts;
@ -5219,6 +5222,7 @@
1729529724AA1CD000D65E66 /* MacPreferencesView.swift in Sources */,
51E4994C24A8734C00B667CB /* RedditFeedProvider-Extensions.swift in Sources */,
1729529324AA1CAA00D65E66 /* AccountsPreferencesView.swift in Sources */,
1769E32D24BD20A0000E1E8E /* EditAccountView.swift in Sources */,
51919FAD24AA8CCA00541E64 /* UnreadCountView.swift in Sources */,
51E498C924A8085D00B667CB /* PseudoFeed.swift in Sources */,
51E498FC24A808BA00B667CB /* FaviconURLFinder.swift in Sources */,