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

View File

@ -8,12 +8,16 @@ class AppData : ObservableObject {
@Published var banks: [Customer] = []
@Published var hasAtLeastOneAccountBeenAdded: Bool = false
init() {
banks = presenter.customers
hasAtLeastOneAccountBeenAdded = banks.isNotEmpty
presenter.addAccountsChangedListener { banks in
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 {
var className: String {

View File

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