1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
* See LICENSE.md
*/
import SwiftUI
import SymLog
struct TransactionsListView: View {
private let symLog = SymLogV(0)
let stack: CallStack
@AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
let navTitle: String
let scopeInfo: ScopeInfo
let transactions: [Transaction]
let showUpDown: Bool
let reloadAllAction: (_ stack: CallStack) async -> ()
let reloadOneAction: ((_ transactionId: String, _ viewHandles: Bool) async throws -> Transaction)
@State private var viewId = UUID()
@State private var upAction: () -> Void = {}
@State private var downAction: () -> Void = {}
var body: some View {
#if PRINT_CHANGES
let _ = Self._printChanges()
let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear
#endif
let count = transactions.count
ScrollViewReader { scrollView in
List {
TransactionsArraySliceV(symLog: symLog,
stack: stack.push(),
scopeInfo: scopeInfo,
transactions: transactions,
reloadOneAction: reloadOneAction)
.padding(.leading, ICONLEADING)
}
.id(viewId)
.listStyle(myListStyle.style).anyView
.refreshable {
symLog.log("refreshing")
await reloadAllAction(stack.push())
}
.navigationBarItems(trailing: HStack {
if showUpDown {
ArrowUpButton(action: upAction)
ArrowDownButton(action: downAction)
} else {
EmptyView()
}
})
.onAppear {
if showUpDown {
upAction = {
withAnimation { scrollView.scrollTo(0) }
}
downAction = {
withAnimation { scrollView.scrollTo(transactions.count - 1) }
}
// downAction()
}
}
} // ScrollView
.navigationTitle(navTitle)
.accessibilityHint(String(localized: "Transaction list"))
.task {
symLog.log(".task ")
await reloadAllAction(stack.push())
}
.overlay {
if transactions.isEmpty {
TransactionsEmptyView(stack: stack.push(), currency: scopeInfo.currency)
}
}
.onAppear {
DebugViewC.shared.setViewID(VIEW_TRANSACTIONLIST, stack: stack.push())
}
}
}
// MARK: -
// used by TransactionsListView, and by BalancesSectionView to show the last 3 transactions
struct TransactionsArraySliceV: View {
let symLog: SymLogV?
let stack: CallStack
let scopeInfo: ScopeInfo
let transactions: [Transaction]
let reloadOneAction: ((_ transactionId: String, _ viewHandles: Bool) async throws -> Transaction)
@EnvironmentObject private var model: WalletModel
var body: some View {
#if PRINT_CHANGES
let _ = Self._printChanges()
let _ = symLog?.vlog() // just to get the # to compare it with .onAppear & onDisappear
#endif
let abortAction = model.abortTransaction
let deleteAction = model.deleteTransaction
let failAction = model.failTransaction
let suspendAction = model.suspendTransaction
let resumeAction = model.resumeTransaction
ForEach(Array(zip(transactions.indices, transactions)), id: \.1) { index, transaction in
NavigationLink {
LazyView {
TransactionSummaryV(stack: stack.push(),
transactionId: transaction.id,
reloadAction: reloadOneAction,
navTitle: nil,
doneAction: nil,
abortAction: abortAction,
deleteAction: deleteAction,
failAction: failAction,
suspendAction: suspendAction,
resumeAction: resumeAction)
}
} label: {
TransactionRowView(transaction: transaction)
}
.id(Int(index))
}
}
}
|