taler-ios

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

ReportView.swift (2374B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-25 Taler Systems S.A.
      3  * See LICENSE.md
      4  */
      5 /**
      6  * @author Marc Stibane
      7  */
      8 import SwiftUI
      9 import taler_swift
     10 import SymLog
     11 
     12 //let BACKUP = "Taler-"
     13 //let PREFIX = "file://"
     14 
     15 /// This view shows the list of backups
     16 struct ReportView: View {
     17     private let symLog = SymLogV(0)
     18     let stack: CallStack
     19     let navTitle: String
     20 
     21     @EnvironmentObject private var model: WalletModel
     22     @EnvironmentObject private var controller: Controller
     23     @AppStorage("minimalistic") var minimalistic: Bool = false
     24     @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
     25 
     26     @State private var creating: Bool = false
     27     @State private var report: String = EMPTYSTRING
     28     @State private var expanded: Bool = false
     29 
     30     private func createReport() {
     31         creating = true
     32         Task {
     33             if let diagnostics = try? await model.getDiagnostics() {
     34                 report = diagnostics
     35             }
     36             creating = false
     37         }
     38     }
     39 
     40     var body: some View {
     41 #if PRINT_CHANGES
     42         let _ = Self._printChanges()
     43         let _ = symLog.vlog()       // just to get the # to compare it with .onAppear & onDisappear
     44 #endif
     45         let buttonTitle = String(localized: "Create Report", comment: "button")
     46 
     47         let reportHint = Text("Tap 'Create Report' to build a report of your wallet's state, to help improve Taler...\nThis report will not enable the receiver to access your money.")
     48 
     49         List {
     50             Section {
     51                 if report.isEmpty {
     52                     reportHint
     53                     Button(buttonTitle) { createReport() }
     54                         .buttonStyle(TalerButtonStyle(type: .bordered, disabled: creating))
     55                         .padding()
     56                 } else {
     57                     Text(report)
     58                         .multilineTextAlignment(.leading)
     59                         .lineLimit(expanded ? nil : 3)
     60                         .onTapGesture {
     61                             expanded.toggle()
     62                         }
     63                     CopyShare(report, image: nil)
     64                 }
     65             }
     66             .listRowSeparator(.hidden)
     67         }
     68         .listStyle(myListStyle.style).anyView
     69         .navigationTitle(navTitle)
     70         .onAppear() {
     71             DebugViewC.shared.setViewID(VIEW_BANK_ACCOUNTS, stack: stack.push())
     72         }
     73     } // body
     74 }