Update transaction lists when adding or updating individual transactions

This commit is contained in:
William Brawner 2021-10-25 21:07:48 -06:00
parent e0467797d9
commit 9f8a8a5a9e
2 changed files with 8 additions and 3 deletions

View file

@ -90,7 +90,8 @@ class TransactionDataStore: ObservableObject {
}
}, receiveValue: { (transaction) in
self.transaction = .success(transaction)
})
self.transactions = ["": .failure(.loading)]
})
}
func deleteTransaction(_ transactionId: String) {
@ -108,6 +109,7 @@ class TransactionDataStore: ObservableObject {
}
}, receiveValue: { (empty) in
self.transaction = .failure(.deleted)
self.transactions = ["": .failure(.loading)]
})
}

View file

@ -22,17 +22,20 @@ struct TransactionListView: View {
TransactionListItemView(transaction)
}
}
case .failure(.loading):
case nil, .failure(.loading):
VStack {
ActivityIndicator(isAnimating: .constant(true), style: .large)
}.onAppear {
if self.requestId == "" {
if transactionDataStore.transactions[requestId] == nil || self.requestId == "" {
self.requestId = transactionDataStore.getTransactions(self.budget.id, categoryId: self.category?.id)
}
}
default:
// TODO: Handle each network failure type
Text("budgets_load_failure")
Button("action_retry", action: {
self.requestId = transactionDataStore.getTransactions(self.budget.id, categoryId: self.category?.id)
})
}
}