Sources/OrgstarMobile/FolderLintScreen.swift

b50ce164c2ff8b87dcc4256e1b3c97994dc431f8
orgstar/Sources/OrgstarMobile/FolderLintScreen.swift

74 lines · 3097 bytes

 1#if os(iOS)
 2import OrgApp
 3import OrgCore
 4import SwiftUI
 5
 6/// Lint All Folders: the problems in every indexed Org file, grouped by file. Tapping one closes
 7/// the list and opens its file at that line. Closing the list stops a run.
 8struct FolderLintScreen: View {
 9    let workspace: WorkspaceModel
10    let session: DocumentSession
11    let open: (String, Int) -> Void
12    @State private var lint = FolderLint()
13    @Environment(\.dismiss) private var dismiss
14
15    var body: some View {
16        let names = FileLint.names(workspace.files)
17        return NavigationStack {
18            List {
19                Section {
20                    VStack(alignment: .leading, spacing: 6) {
21                        Text(lint.summary).foregroundStyle(.secondary)
22                        if lint.isRunning { ProgressView(value: Double(lint.checked), total: Double(max(1, lint.total))) }
23                    }
24                }
25                ForEach(lint.files ?? []) { file in
26                    Section {
27                        ForEach(file.findings) { finding in
28                            Button {
29                                dismiss()
30                                open(file.path, finding.offset)
31                            } label: {
32                                row(finding)
33                            }
34                        }
35                    } header: {
36                        Text(verbatim: names[file.path] ?? file.path)
37                    }
38                }
39            }
40            .overlay {
41                if lint.files?.isEmpty == true { ContentUnavailableView("No problems found", systemImage: "checkmark.circle") }
42            }
43            .navigationTitle("Lint All Folders")
44            .navigationBarTitleDisplayMode(.inline)
45            .toolbar {
46                ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } }
47                ToolbarItem(placement: .cancellationAction) {
48                    if lint.isRunning {
49                        Button("Stop") { lint.stop() }
50                    } else {
51                        Button("Check Again") { lint.run(workspace: workspace, session: session) }
52                    }
53                }
54            }
55        }
56        .onAppear { lint.run(workspace: workspace, session: session) }
57        .onDisappear { lint.stop() }
58    }
59
60    private func row(_ finding: LintFinding) -> some View {
61        HStack(alignment: .firstTextBaseline, spacing: 10) {
62            Image(systemName: finding.trust == .high ? "xmark.octagon.fill" : "exclamationmark.triangle.fill")
63                .foregroundStyle(finding.trust == .high ? Color.red : Color.orange)
64                .accessibilityLabel(FileLint.severity(finding))
65            VStack(alignment: .leading, spacing: 2) {
66                Text(finding.message).foregroundStyle(Color.primary)
67                Text("Line \(finding.line) · \(finding.checker.rawValue)", comment: "Lint File: a problem's line and checker")
68                    .font(.caption)
69                    .foregroundStyle(Color.secondary)
70            }
71        }
72    }
73}
74#endif
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form