2019-10-12 19:03:50 +00:00
|
|
|
|
2019-10-01 03:31:22 +00:00
|
|
|
//
|
|
|
|
// 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
|
2019-10-01 03:31:22 +00:00
|
|
|
|
2019-10-02 04:57:27 +00:00
|
|
|
struct BudgetListsView: View {
|
2022-05-18 01:04:27 +00:00
|
|
|
@EnvironmentObject var dataStore: DataStore
|
2019-10-01 03:31:22 +00:00
|
|
|
|
|
|
|
var body: some View {
|
2022-01-03 17:56:43 +00:00
|
|
|
InlineLoadingView(
|
2022-05-18 01:04:27 +00:00
|
|
|
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)
|
2021-09-11 15:01:22 +00:00
|
|
|
}
|
2019-10-01 03:31:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct BudgetListItemView: View {
|
2022-05-18 01:04:27 +00:00
|
|
|
@EnvironmentObject var dataStore: DataStore
|
2021-11-03 17:17:18 +00:00
|
|
|
let budget: Budget
|
2021-12-08 03:22:06 +00:00
|
|
|
|
2019-10-01 03:31:22 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2019-10-01 03:31:22 +00:00
|
|
|
}
|
2021-10-10 03:23:49 +00:00
|
|
|
)
|
2019-10-01 03:31:22 +00:00
|
|
|
}
|
2021-12-08 03:22:06 +00:00
|
|
|
|
2021-10-06 01:26:54 +00:00
|
|
|
init (_ budget: Budget) {
|
2019-10-01 03:31:22 +00:00
|
|
|
self.budget = budget
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-19 22:18:06 +00:00
|
|
|
#if DEBUG
|
2019-10-12 19:03:50 +00:00
|
|
|
struct BudgetListsView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2021-10-06 01:26:54 +00:00
|
|
|
BudgetListsView()
|
2019-10-12 19:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-19 22:18:06 +00:00
|
|
|
#endif
|