gitbay/Views/Builds/BuildLogView.swift
55 lines · 1730 bytes
1import SwiftUI
2
3/// `build log` — plain text, can be large. Monospaced, both-axis scroll.
4struct BuildLogView: View {
5
6 private let client: GitbayClient
7 private let repo: String
8 private let number: Int64
9 @State private var state: LoadState<String> = .loading
10
11 init(client: GitbayClient, repo: String, number: Int64) {
12 self.client = client
13 self.repo = repo
14 self.number = number
15 }
16
17 var body: some View {
18 ZStack {
19 Color.clear
20 if let log = state.value {
21 if log.isEmpty {
22 ContentUnavailableView {
23 Label("No log yet", systemImage: "doc.text")
24 }
25 } else {
26 ScrollView([.horizontal, .vertical]) {
27 Text(log)
28 .font(.gbMono(.caption2))
29 .frame(maxWidth: .infinity, alignment: .leading)
30 .padding(12)
31 .textSelection(.enabled)
32 }
33 }
34 }
35 }
36 .overlay { LoadStateOverlay(state: state) }
37 .navigationTitle("Build #\(number)")
38 .navigationBarTitleDisplayMode(.inline)
39 .task {
40 do {
41 state = .loaded(try await client.readText(["build", "log", repo, String(number)]))
42 } catch {
43 state = .from(error)
44 }
45 }
46 .refreshable {
47 state = .loading
48 do {
49 state = .loaded(try await client.readText(["build", "log", repo, String(number)]))
50 } catch {
51 state = .from(error)
52 }
53 }
54 }
55}