DomainDig/SubdomainsSectionView.swift
139 lines · 5227 bytes
1 symbol in this file
1import SwiftUI
2
3// One inspection section: the discovered subdomains card. Pure presentation
4// over the view model's report data; the shared primitives it builds on
5// (CardView, SectionTitleView, LabeledValueRow, ResultColors, appLoadingStyle)
6// live in ResultPrimitives.swift.
7
8struct SubdomainsSectionView: View {
9 @Environment(\.appDensity) private var appDensity
10 @Binding var isCollapsed: Bool
11 let rows: [SubdomainRowViewData]
12 let groups: [SubdomainGroup]
13 let loading: Bool
14 let error: String?
15 let provenance: SectionProvenance?
16 let confidence: ConfidenceLevel?
17 let showsExtendedPlaceholder: Bool
18 let extendedCount: Int
19 let extendedLoading: Bool
20 let extendedError: String?
21 let onLoadExtended: (() -> Void)?
22
23 init(
24 isCollapsed: Binding<Bool>,
25 rows: [SubdomainRowViewData],
26 groups: [SubdomainGroup],
27 loading: Bool,
28 error: String?,
29 provenance: SectionProvenance?,
30 confidence: ConfidenceLevel?,
31 showsExtendedPlaceholder: Bool,
32 extendedCount: Int = 0,
33 extendedLoading: Bool = false,
34 extendedError: String? = nil,
35 onLoadExtended: (() -> Void)? = nil
36 ) {
37 _isCollapsed = isCollapsed
38 self.rows = rows
39 self.groups = groups
40 self.loading = loading
41 self.error = error
42 self.provenance = provenance
43 self.confidence = confidence
44 self.showsExtendedPlaceholder = showsExtendedPlaceholder
45 self.extendedCount = extendedCount
46 self.extendedLoading = extendedLoading
47 self.extendedError = extendedError
48 self.onLoadExtended = onLoadExtended
49 }
50
51 var body: some View {
52 CollapsibleSectionView(title: "Subdomains", isCollapsed: $isCollapsed, subtitle: "\(rows.count) found") {
53 CardView(allowsHorizontalScroll: false) {
54 SectionTrustMetadataView(provenance: provenance, confidence: confidence)
55 if loading {
56 ProgressView("Checking certificate transparency…")
57 .appLoadingStyle()
58 } else if rows.isEmpty {
59 MessageRowView(text: error ?? "No passive subdomains found", isError: false)
60 if showsExtendedPlaceholder {
61 MessageRowView(text: "Extended subdomain discovery available in Pro+", isError: false)
62 .padding(.top, 4)
63 }
64 } else {
65 if let onLoadExtended, extendedCount == 0, !extendedLoading, !showsExtendedPlaceholder {
66 Button("Load extended results") {
67 onLoadExtended()
68 }
69 .buttonStyle(.bordered)
70 .font(appDensity.font(.caption2))
71 }
72 groupList
73 subdomainRows
74 extendedStatus
75 }
76 }
77 }
78 }
79
80 @ViewBuilder
81 private var extendedStatus: some View {
82 if extendedLoading {
83 ProgressView("Loading extended subdomains…")
84 .appLoadingStyle()
85 .padding(.top, 4)
86 } else if extendedCount > 0 {
87 MessageRowView(text: "\(extendedCount) extended results included", isError: false)
88 .padding(.top, 4)
89 } else if let extendedError {
90 MessageRowView(text: extendedError, isError: false)
91 .padding(.top, 4)
92 } else if showsExtendedPlaceholder {
93 MessageRowView(text: "Extended subdomain discovery available in Pro+", isError: false)
94 .padding(.top, 4)
95 }
96 }
97
98 @ViewBuilder
99 private var groupList: some View {
100 if !groups.isEmpty {
101 Text("Groups")
102 .font(appDensity.font(.caption2))
103 .foregroundStyle(ThemeToken.textSecondary)
104 ForEach(groups) { group in
105 HStack {
106 Text("\(group.label).*")
107 .font(appDensity.font(.caption))
108 .foregroundStyle(ThemeToken.info)
109 Spacer()
110 Text("\(group.subdomains.count)")
111 .font(appDensity.font(.caption2))
112 .foregroundStyle(ThemeToken.textSecondary)
113 }
114 }
115 }
116 }
117
118 @ViewBuilder
119 private var subdomainRows: some View {
120 ForEach(rows) { row in
121 HStack(spacing: 8) {
122 Text(row.hostname)
123 .font(appDensity.font(.caption))
124 .foregroundStyle(.primary)
125 .textSelection(.enabled)
126 Spacer()
127 if row.isInteresting {
128 Text("Interesting")
129 .font(.system(.caption2, design: .monospaced))
130 .foregroundStyle(ThemeToken.warning)
131 .padding(.horizontal, 8)
132 .padding(.vertical, 4)
133 .background(ThemeToken.warningSurface)
134 .clipShape(Capsule())
135 }
136 }
137 }
138 }
139}