krz/domain-dig

an ios app for DNS & SSL analysis

clone: git clone https://gitbay.org/krz/domain-dig.git

v5.0.3: DomainDig/BatchSweepSummaryView.swift · raw

 1import SwiftUI
 2
 3struct BatchSweepSummaryView: View {
 4    @Bindable var viewModel: DomainViewModel
 5    let summary: BatchSweepSummary
 6
 7    @State private var showUnchangedDomains = false
 8
 9    private var visibleResults: [BatchLookupResult] {
10        if showUnchangedDomains {
11            return summary.results
12        }
13
14        return summary.results.filter(\.hasMeaningfulChange)
15    }
16
17    var body: some View {
18        NavigationStack {
19            List {
20                Section("Overview") {
21                    statRow(label: "Checked", value: "\(summary.totalDomains)")
22                    statRow(label: "Changed", value: "\(summary.changedDomains)")
23                    statRow(label: "Warnings", value: "\(summary.warningDomains)")
24                    statRow(label: "Unchanged", value: "\(summary.unchangedDomains)")
25                }
26
27                Section {
28                    Toggle("Show unchanged domains", isOn: $showUnchangedDomains)
29                }
30
31                Section(visibleResults.isEmpty ? "Changed Domains" : "Results") {
32                    if visibleResults.isEmpty {
33                        Text("No domains with changes or warnings")
34                            .font(.system(.caption, design: .monospaced))
35                            .foregroundStyle(Color(.appTextSecondary))
36                    } else {
37                        ForEach(visibleResults) { result in
38                            if let entry = viewModel.historyEntry(for: result) {
39                                NavigationLink {
40                                    HistoryDetailView(viewModel: viewModel, entry: entry)
41                                } label: {
42                                    BatchResultRowView(result: result)
43                                }
44                            } else {
45                                BatchResultRowView(result: result)
46                            }
47                        }
48                    }
49                }
50            }
51            .navigationTitle(summary.source == .watchlistRefresh ? "Sweep Summary" : "Batch Summary")
52        }
53    }
54
55    private func statRow(label: String, value: String) -> some View {
56        HStack {
57            Text(label)
58                .font(.system(.caption, design: .monospaced))
59                .foregroundStyle(Color(.appTextSecondary))
60            Spacer()
61            Text(value)
62                .font(.system(.callout, design: .monospaced))
63                .foregroundStyle(.primary)
64        }
65    }
66}