Add search functionality to transaction lists
This commit is contained in:
parent
20b56fb05a
commit
bcab5fa078
1 changed files with 11 additions and 3 deletions
|
@ -14,6 +14,7 @@ struct TransactionListView: View {
|
|||
@EnvironmentObject var transactionDataStore: TransactionDataStore
|
||||
@State var requestId: String = ""
|
||||
@State var isAddingTransaction = false
|
||||
@State var search: String = ""
|
||||
let header: AnyView?
|
||||
|
||||
@ViewBuilder
|
||||
|
@ -28,8 +29,13 @@ struct TransactionListView: View {
|
|||
}
|
||||
ForEach(transactions.keys, id: \.self) { (key: String) in
|
||||
Group {
|
||||
let filtered = search.isEmpty ? transactions[key]! : transactions[key]!.filter { $0.title.lowercased().contains(search.lowercased())
|
||||
|| $0.description?.lowercased().contains(search.lowercased()) ?? false
|
||||
|| $0.amount.toCurrencyString().contains(search)
|
||||
}
|
||||
if !filtered.isEmpty {
|
||||
Section(header: Text(key)) {
|
||||
ForEach(transactions[key]!) { transaction in
|
||||
ForEach(filtered) { transaction in
|
||||
TransactionListItemView(transaction)
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +43,7 @@ struct TransactionListView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
var body: some View {
|
||||
|
@ -45,6 +52,7 @@ struct TransactionListView: View {
|
|||
List {
|
||||
TransactionList(transactions)
|
||||
}
|
||||
.searchable(text: $search)
|
||||
.sheet(isPresented: $isAddingTransaction, content: {
|
||||
AddTransactionView(showSheet: $isAddingTransaction, budgetId: self.budget.id)
|
||||
.navigationBarTitle("add_transaction")
|
||||
|
|
Loading…
Reference in a new issue