Fix account selection showing wrong sheet upon selection

This commit is contained in:
Rizwan Mohamed Ibrahim
2020-07-09 19:55:58 +05:30
parent 91f2479b96
commit 7c30749625
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 {
Button(action: {
self.selectedAccountType = AccountType.onMyMac
self.isAddPresented = true
}) {
SettingsAccountLabelView(
accountImage: AppAssets.image(for: .onMyMac),
accountLabel: Account.defaultLocalAccountName
)
}
Button(action: {
self.selectedAccountType = AccountType.feedbin
self.isAddPresented = true
}) {
SettingsAccountLabelView(
accountImage: AppAssets.image(for: .feedbin),
accountLabel: "Feedbin"
)
ForEach(model.accounts) { account in
Button(action: {
model.selectedAccountType = account.accountType
}) {
SettingsAccountLabelView(
accountImage: account.image,
accountLabel: account.name
)
}
}
}
.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()
}
}