Implemented hiding update all accounts' transaction when no account has been added; Implemented array extension property isNotEmpty

This commit is contained in:
dankito 2020-07-31 01:07:36 +02:00
parent 766209c1e6
commit ae1b209db4
4 changed files with 19 additions and 4 deletions

View File

@ -113,10 +113,12 @@ struct ContentView: View {
// due to a SwiftUI bug this cannot be set in AccountsTab directly, so i have to do it here // due to a SwiftUI bug this cannot be set in AccountsTab directly, so i have to do it here
self.navigationBarTitle = "Accounts" self.navigationBarTitle = "Accounts"
if data.hasAtLeastOneAccountBeenAdded {
self.leadingNavigationBarItem = AnyView(UpdateButton { _ in self.leadingNavigationBarItem = AnyView(UpdateButton { _ in
self.presenter.updateAccountsTransactionsAsync { _ in } self.presenter.updateAccountsTransactionsAsync { _ in }
}) })
} }
}
} }

View File

@ -8,12 +8,16 @@ class AppData : ObservableObject {
@Published var banks: [Customer] = [] @Published var banks: [Customer] = []
@Published var hasAtLeastOneAccountBeenAdded: Bool = false
init() { init() {
banks = presenter.customers banks = presenter.customers
hasAtLeastOneAccountBeenAdded = banks.isNotEmpty
presenter.addAccountsChangedListener { banks in presenter.addAccountsChangedListener { banks in
self.banks = banks self.banks = banks
self.hasAtLeastOneAccountBeenAdded = banks.isNotEmpty
} }
} }

View File

@ -90,6 +90,15 @@ extension Array where Element == NSDecimalNumber {
} }
extension Array {
var isNotEmpty: Bool {
return !isEmpty
}
}
extension NSObject { extension NSObject {
var className: String { var className: String {

View File

@ -11,7 +11,7 @@ struct AccountsTab: View {
var body: some View { var body: some View {
VStack { VStack {
if data.banks.isEmpty == false { if data.banks.isNotEmpty {
Form { Form {
AllBanksListItem(banks: data.banks) AllBanksListItem(banks: data.banks)