2021-12-08 03:22:06 +00:00
|
|
|
//
|
|
|
|
// RecurringTransactionView.swift
|
|
|
|
// Twigs
|
|
|
|
//
|
|
|
|
// Created by William Brawner on 12/6/21.
|
|
|
|
// Copyright © 2021 William Brawner. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-01-03 17:56:43 +00:00
|
|
|
import TwigsCore
|
2021-12-08 03:22:06 +00:00
|
|
|
|
|
|
|
struct RecurringTransactionsListView: View {
|
2022-05-18 01:04:27 +00:00
|
|
|
@EnvironmentObject var dataStore: DataStore
|
2021-12-08 03:22:06 +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.recurringTransactions,
|
|
|
|
action: { await self.dataStore.getRecurringTransactions() },
|
2022-01-03 17:56:43 +00:00
|
|
|
errorTextLocalizedStringKey: "Failed to load recurring transactions"
|
|
|
|
) { (transactions: [RecurringTransaction]) in
|
2021-12-08 03:22:06 +00:00
|
|
|
List {
|
|
|
|
ForEach(transactions) { transaction in
|
|
|
|
RecurringTransactionsListItemView(transaction)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-14 13:15:32 +00:00
|
|
|
#if DEBUG
|
2021-12-08 03:22:06 +00:00
|
|
|
struct RecurringTransactionView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2022-05-18 01:04:27 +00:00
|
|
|
RecurringTransactionsListView()
|
2021-12-08 03:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-14 13:15:32 +00:00
|
|
|
#endif
|
2021-12-08 03:22:06 +00:00
|
|
|
|
|
|
|
struct RecurringTransactionsListItemView: View {
|
2022-05-18 01:04:27 +00:00
|
|
|
@EnvironmentObject var dataStore: DataStore
|
2021-12-08 03:22:06 +00:00
|
|
|
let transaction: RecurringTransaction
|
|
|
|
|
|
|
|
init (_ transaction: RecurringTransaction) {
|
|
|
|
self.transaction = transaction
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
NavigationLink(
|
2022-01-05 02:51:38 +00:00
|
|
|
tag: transaction,
|
2022-05-18 01:04:27 +00:00
|
|
|
selection: $dataStore.selectedRecurringTransaction,
|
2022-01-05 02:51:38 +00:00
|
|
|
destination: {
|
|
|
|
RecurringTransactionDetailsView()
|
2021-12-08 03:22:06 +00:00
|
|
|
.navigationBarTitle("details", displayMode: .inline)
|
2022-01-05 02:51:38 +00:00
|
|
|
}
|
2021-12-08 03:22:06 +00:00
|
|
|
) {
|
|
|
|
HStack {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(verbatim: transaction.title)
|
|
|
|
.lineLimit(1)
|
|
|
|
.font(.headline)
|
|
|
|
if let description = transaction.description?.trimmingCharacters(in: CharacterSet([" "])), !description.isEmpty {
|
|
|
|
Text(verbatim: description)
|
|
|
|
.lineLimit(1)
|
|
|
|
.font(.subheadline)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.multilineTextAlignment(.trailing)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
VStack(alignment: .trailing) {
|
|
|
|
Text(verbatim: transaction.amount.toCurrencyString())
|
|
|
|
.foregroundColor(transaction.expense ? .red : .green)
|
|
|
|
.multilineTextAlignment(.trailing)
|
|
|
|
}
|
|
|
|
.padding(.leading)
|
|
|
|
}.padding(5.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-14 13:15:32 +00:00
|
|
|
#if DEBUG
|
2021-12-08 03:22:06 +00:00
|
|
|
struct RecurringTransactionsListItemView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
RecurringTransactionsListItemView(MockRecurringTransactionRepository.transaction)
|
|
|
|
}
|
|
|
|
}
|
2021-12-14 13:15:32 +00:00
|
|
|
#endif
|