taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 1a5c9a9efceba7912c3ef826961d73defb316b90
parent 4e71ef07ac6965ba311aa30349e72657d31f8451
Author: Marc Stibane <marc@taler.net>
Date:   Mon, 24 Jul 2023 16:45:31 +0200

extension TransactionsListView.Content => TransactionsRowsView

Diffstat:
MTalerWallet1/Views/Transactions/TransactionsListView.swift | 154+++++++++++++++++++++++++++++++++++--------------------------------------------
1 file changed, 68 insertions(+), 86 deletions(-)

diff --git a/TalerWallet1/Views/Transactions/TransactionsListView.swift b/TalerWallet1/Views/Transactions/TransactionsListView.swift @@ -16,68 +16,74 @@ struct TransactionsListView: View { let reloadAllAction: () async -> () let reloadOneAction: ((_ transactionId: String) async throws -> Transaction) + @State private var viewId = UUID() + @State private var upAction: () -> Void = {} + @State private var downAction: () -> Void = {} var body: some View { #if DEBUG let _ = Self._printChanges() let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear #endif let count = transactions.count - Content(symLog: symLog, - currency: currency, - transactions: transactions, - showUpDown: showUpDown, - myListStyle: $myListStyle, - reloadAllAction: reloadAllAction, - reloadOneAction: reloadOneAction) - .navigationTitle(navTitle) - .onAppear { - DebugViewC.shared.setViewID(VIEW_TRANSACTIONLIST) + ScrollViewReader { scrollView in + List { + TransactionsRowsView(symLog: symLog, + currency: currency, + transactions: transactions, +// reloadAllAction: reloadAllAction, + reloadOneAction: reloadOneAction) } - .task { - symLog.log(".task ") + .id(viewId) + .listStyle(myListStyle.style).anyView + .refreshable { + symLog.log("refreshing") await reloadAllAction() } + .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) + .task { + symLog.log(".task ") + await reloadAllAction() + } + .overlay { + if transactions.isEmpty { + TransactionsEmptyView(currency: currency) + } + } + .onAppear { + DebugViewC.shared.setViewID(VIEW_TRANSACTIONLIST) + } } } // MARK: - -extension TransactionsListView { - struct Content: View { +//extension TransactionsListView { + struct TransactionsRowsView: View { let symLog: SymLogV? let currency: String let transactions: [Transaction] - let showUpDown: Bool - @Binding var myListStyle: MyListStyle - let reloadAllAction: () async -> () +// let reloadAllAction: () async -> () let reloadOneAction: ((_ transactionId: String) async throws -> Transaction) @EnvironmentObject private var model: WalletModel - - @State private var upAction: () -> Void = {} - @State private var downAction: () -> Void = {} - -// func removeItems(at offsets: IndexSet) { -// let transactions = model.transactions -// var idsToDelete: [String] = [] -// for n in offsets { // save IDs of transactions -// let common = transactions[n].common -// idsToDelete.append(common.transactionId) -// } -// // then remove items from the list model (and the view) -// model.transactions.remove(atOffsets: offsets) -// // finally tell wallet-core to delete the saved IDs -// Task { // delete this transaction from wallet-core -// for transactionId in idsToDelete { -// do { -// try await deleteAction(transactionId) -// symLog?.log("deleted \(transactionId)") -// } catch { // TODO: error -// symLog?.log(error.localizedDescription) -// } -// } -// } -// } - - @State var viewId = UUID() var body: some View { #if DEBUG let _ = Self._printChanges() @@ -88,54 +94,30 @@ extension TransactionsListView { let failAction = model.failTransaction let suspendAction = model.suspendTransaction let resumeAction = model.resumeTransaction - ScrollViewReader { scrollView in - List { - ForEach(Array(zip(transactions.indices, transactions)), id: \.1) { index, transaction in - NavigationLink { LazyView { // whole row like in a tableView - // pending may not be deleted, but only aborted - TransactionDetailView(transactionId: transaction.id, - reloadAction: reloadOneAction, - abortAction: abortAction, - deleteAction: deleteAction, - failAction: failAction, - suspendAction: suspendAction, - resumeAction: resumeAction) - }} label: { - TransactionRowView(transaction: transaction) - } + ForEach(Array(zip(transactions.indices, transactions)), id: \.1) { index, transaction in + NavigationLink { LazyView { // whole row like in a tableView + TransactionDetailView(transactionId: transaction.id, + reloadAction: reloadOneAction, + abortAction: abortAction, + deleteAction: deleteAction, + failAction: failAction, + suspendAction: suspendAction, + resumeAction: resumeAction) + }} label: { + TransactionRowView(transaction: transaction) } -// .onDelete(perform: removeItems) // delete this row from the list - }.id(viewId) - .listStyle(myListStyle.style).anyView - .refreshable { - symLog?.log("refreshing") - await reloadAllAction() - } - .onAppear { - if showUpDown { - upAction = { withAnimation { scrollView.scrollTo(0) }} - downAction = { withAnimation { scrollView.scrollTo(transactions.count - 1) }} - downAction() - } - } - .overlay { - if transactions.isEmpty { - TransactionsEmptyView(currency: currency) - } - } - } - .navigationBarItems(trailing: HStack { - EmptyView() - if showUpDown { - ArrowUpButton(action: upAction) - ArrowDownButton(action: downAction) + .id(Int(index)) } - }) + // pending may not be deleted, but only aborted +// .onDelete(perform: removeItems) // delete this row from the list } } -} +//} +// MARK: - +#if DEBUG //struct TransactionsView_Previews: PreviewProvider { // static var previews: some View { // TransactionsView() // } //} +#endif