twigs-ios/Twigs/Budget/BudgetListsView.swift

69 lines
1.7 KiB
Swift
Raw Normal View History

//
// BudgetsView.swift
// Budget
//
// Created by Billy Brawner on 9/30/19.
// Copyright © 2019 William Brawner. All rights reserved.
//
import SwiftUI
import Combine
2022-01-03 17:56:43 +00:00
import TwigsCore
struct BudgetListsView: View {
@EnvironmentObject var dataStore: DataStore
var body: some View {
2022-01-03 17:56:43 +00:00
InlineLoadingView(
data: $dataStore.budgets,
action: { await self.dataStore.getBudgets(count: nil, page: nil) },
2022-01-03 17:56:43 +00:00
errorTextLocalizedStringKey: "budgets_load_failure"
) { (budgets: [Budget]) in
2022-05-18 03:13:48 +00:00
ForEach(budgets) { budget in
BudgetListItemView(budget)
}
}
}
}
struct BudgetListItemView: View {
@EnvironmentObject var dataStore: DataStore
2021-11-03 17:17:18 +00:00
let budget: Budget
var body: some View {
2021-11-03 17:17:18 +00:00
Button(
action: {
2022-05-18 01:55:28 +00:00
Task {
await self.dataStore.selectBudget(budget)
}
2021-11-03 17:17:18 +00:00
},
label: {
VStack(alignment: .leading) {
Text(verbatim: budget.name)
.foregroundColor(.primary)
.lineLimit(1)
if budget.description?.isEmpty == false {
Text(verbatim: budget.description!)
.font(.subheadline)
.foregroundColor(.secondary)
.lineLimit(1)
}
}
}
)
}
init (_ budget: Budget) {
self.budget = budget
}
}
#if DEBUG
struct BudgetListsView_Previews: PreviewProvider {
static var previews: some View {
BudgetListsView()
}
}
#endif