Move category header into transaction list for style consistency
This commit is contained in:
parent
7d8ec85f05
commit
8aa5119e3e
3 changed files with 29 additions and 10 deletions
|
@ -39,7 +39,7 @@ struct CategoryDetailsView: View {
|
|||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
TransactionListView(self.budget, category: category, header: VStack {
|
||||
Text(verbatim: category.description ?? "")
|
||||
.padding()
|
||||
HStack {
|
||||
|
@ -47,8 +47,8 @@ struct CategoryDetailsView: View {
|
|||
LabeledCounter(title: middleLabel, amount: spent)
|
||||
LabeledCounter(title: LocalizedStringKey("amount_remaining"), amount: remaining)
|
||||
}
|
||||
TransactionListView(self.budget, category: category)
|
||||
}.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
|
||||
}.frame(maxWidth: .infinity, alignment: .center).eraseToAnyView())
|
||||
|
||||
.onAppear {
|
||||
if sumRequest == "" || !sumRequest.contains(category.id) {
|
||||
sumRequest = transactionDataStore.sum(budgetId: nil, categoryId: category.id, from: nil, to: nil)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
extension Int {
|
||||
func toDecimalString() -> String {
|
||||
|
@ -22,3 +23,8 @@ extension Int {
|
|||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func eraseToAnyView() -> AnyView {
|
||||
return AnyView(self)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,17 +13,29 @@ struct TransactionListView: View {
|
|||
@EnvironmentObject var transactionDataStore: TransactionDataStore
|
||||
@State var requestId: String = ""
|
||||
@State var isAddingTransaction = false
|
||||
let header: AnyView?
|
||||
|
||||
@ViewBuilder
|
||||
var body: some View {
|
||||
switch transactionDataStore.transactions[requestId] {
|
||||
case .success(let transactions):
|
||||
List {
|
||||
ForEach(transactions.keys, id: \.self) { (key: String) in
|
||||
Group {
|
||||
Section(header: Text(key)) {
|
||||
ForEach(transactions[key]!) { transaction in
|
||||
TransactionListItemView(transaction)
|
||||
Group {
|
||||
if transactions.isEmpty {
|
||||
Text("no_transactions")
|
||||
} else {
|
||||
List {
|
||||
if let header = header {
|
||||
Section {
|
||||
header
|
||||
}
|
||||
}
|
||||
ForEach(transactions.keys, id: \.self) { (key: String) in
|
||||
Group {
|
||||
Section(header: Text(key)) {
|
||||
ForEach(transactions[key]!) { transaction in
|
||||
TransactionListItemView(transaction)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,9 +74,10 @@ struct TransactionListView: View {
|
|||
|
||||
let budget: Budget
|
||||
let category: Category?
|
||||
init(_ budget: Budget, category: Category? = nil) {
|
||||
init(_ budget: Budget, category: Category? = nil, header: AnyView? = nil) {
|
||||
self.budget = budget
|
||||
self.category = category
|
||||
self.header = header
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue