gitbay/Views/MRs/RangeDiffView.swift
32 lines · 1153 bytes
1 symbol in this file
1import SwiftUI
2
3/// git's range-diff between two revisions of a merge request, as the
4/// command prints it — the same monospaced text treatment as a build log.
5struct RangeDiffView: View {
6
7 @State private var model: RangeDiffViewModel
8
9 init(client: GitbayClient, repo: String, number: Int64, from: String, to: String) {
10 _model = State(initialValue: RangeDiffViewModel(
11 client: client, repoPath: repo, number: number, from: from, to: to))
12 }
13
14 var body: some View {
15 ZStack {
16 Color.clear
17 if let text = model.state.value {
18 ScrollView([.horizontal, .vertical]) {
19 Text(text)
20 .font(.gbMono(.caption2))
21 .frame(maxWidth: .infinity, alignment: .leading)
22 .padding(12)
23 .textSelection(.enabled)
24 }
25 }
26 }
27 .overlay { LoadStateOverlay(state: model.state) }
28 .navigationTitle("\(model.from.prefix(7))…\(model.to.prefix(7))")
29 .navigationBarTitleDisplayMode(.inline)
30 .task { await model.load() }
31 }
32}