Merge pull request #2239 from rizwankce/fix/add-account-action

Fix account selection
This commit is contained in:
Maurice Parker 2020-07-09 09:31:06 -05:00 committed by GitHub
commit d16c1678f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 22 deletions

View File

@ -0,0 +1,41 @@
//
// SettingsAddAccountModel.swift
// Multiplatform iOS
//
// Created by Rizwan on 09/07/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
import Account
import RSCore
class SettingsAddAccountModel: ObservableObject {
struct SettingsAddAccount: Identifiable {
var id: Int { accountType.rawValue }
let name: String
let accountType: AccountType
var image: RSImage {
AppAssets.image(for: accountType)!
}
}
@Published var accounts: [SettingsAddAccount] = []
@Published var isAddPresented = false
@Published var selectedAccountType: AccountType? = nil {
didSet {
selectedAccountType != nil ? (isAddPresented = true) : (isAddPresented = false)
}
}
init() {
self.accounts = [
SettingsAddAccount(name: Account.defaultLocalAccountName, accountType: .onMyMac),
SettingsAddAccount(name: "Feedbin", accountType: .feedbin)
]
}
}

View File

@ -10,36 +10,27 @@ import SwiftUI
import Account
struct SettingsAddAccountView: View {
@State private var isAddPresented = false
@State private var selectedAccountType: AccountType = .onMyMac
@StateObject private var model = SettingsAddAccountModel()
var body: some View {
List {
ForEach(model.accounts) { account in
Button(action: {
self.selectedAccountType = AccountType.onMyMac
self.isAddPresented = true
model.selectedAccountType = account.accountType
}) {
SettingsAccountLabelView(
accountImage: AppAssets.image(for: .onMyMac),
accountLabel: Account.defaultLocalAccountName
accountImage: account.image,
accountLabel: account.name
)
}
Button(action: {
self.selectedAccountType = AccountType.feedbin
self.isAddPresented = true
}) {
SettingsAccountLabelView(
accountImage: AppAssets.image(for: .feedbin),
accountLabel: "Feedbin"
)
}
}
.listStyle(InsetGroupedListStyle())
.sheet(isPresented: $isAddPresented) {
if selectedAccountType == .onMyMac {
.sheet(isPresented: $model.isAddPresented) {
if model.selectedAccountType == .onMyMac {
SettingsLocalAccountView()
}
if selectedAccountType == .feedbin {
if model.selectedAccountType == .feedbin {
SettingsFeedbinAccountView()
}
}

View File

@ -672,6 +672,7 @@
55E15BCB229D65A900D6602A /* AccountsReaderAPI.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55E15BC1229D65A900D6602A /* AccountsReaderAPI.xib */; };
55E15BCC229D65A900D6602A /* AccountsReaderAPIWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E15BCA229D65A900D6602A /* AccountsReaderAPIWindowController.swift */; };
5F323809231DF9F000706F6B /* VibrantTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F323808231DF9F000706F6B /* VibrantTableViewCell.swift */; };
65422D1724B75CD1008A2FA2 /* SettingsAddAccountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65422D1624B75CD1008A2FA2 /* SettingsAddAccountModel.swift */; };
6581C73820CED60100F4AD34 /* SafariExtensionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6581C73720CED60100F4AD34 /* SafariExtensionHandler.swift */; };
6581C73A20CED60100F4AD34 /* SafariExtensionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6581C73920CED60100F4AD34 /* SafariExtensionViewController.swift */; };
6581C73D20CED60100F4AD34 /* SafariExtensionViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6581C73B20CED60100F4AD34 /* SafariExtensionViewController.xib */; };
@ -2088,6 +2089,7 @@
55E15BC1229D65A900D6602A /* AccountsReaderAPI.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AccountsReaderAPI.xib; sourceTree = "<group>"; };
55E15BCA229D65A900D6602A /* AccountsReaderAPIWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsReaderAPIWindowController.swift; sourceTree = "<group>"; };
5F323808231DF9F000706F6B /* VibrantTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VibrantTableViewCell.swift; sourceTree = "<group>"; };
65422D1624B75CD1008A2FA2 /* SettingsAddAccountModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsAddAccountModel.swift; sourceTree = "<group>"; };
6543108B2322D90900658221 /* common */ = {isa = PBXFileReference; lastKnownFileType = folder; path = common; sourceTree = "<group>"; };
6581C73320CED60000F4AD34 /* Subscribe to Feed.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Subscribe to Feed.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
6581C73420CED60100F4AD34 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
@ -3161,6 +3163,7 @@
isa = PBXGroup;
children = (
65ACE48324B4779B003AE06A /* SettingsAddAccountView.swift */,
65422D1624B75CD1008A2FA2 /* SettingsAddAccountModel.swift */,
65ACE48524B477C9003AE06A /* SettingsAccountLabelView.swift */,
65ACE48724B48020003AE06A /* SettingsLocalAccountView.swift */,
65ACE48924B4C2D8003AE06A /* SettingsFeedbinAccountView.swift */,
@ -5069,6 +5072,7 @@
51E4991E24A8094300B667CB /* RSImage-AppIcons.swift in Sources */,
51E499D824A912C200B667CB /* SceneModel.swift in Sources */,
5177470E24B2FF6F00EB0F74 /* ArticleView.swift in Sources */,
65422D1724B75CD1008A2FA2 /* SettingsAddAccountModel.swift in Sources */,
5177471424B37D4000EB0F74 /* PreloadedWebView.swift in Sources */,
517B2EBC24B3E62A001AC46C /* WrapperScriptMessageHandler.swift in Sources */,
51919FB324AAB97900541E64 /* FeedIconImageLoader.swift in Sources */,