krz/hutch

an ios client for sourcehut

clone: git clone https://gitbay.org/krz/hutch.git

v2.12.0: Hutch/Views/Repositories/RepositorySummarySupport.swift · raw

 1import SwiftUI
 2
 3enum RepositoryBuildStatus: Sendable {
 4    case success
 5    case failed
 6    case running
 7    case none
 8}
 9
10struct RepositoryCloneURLs {
11    let readOnly: String
12    let readWrite: String
13}
14
15func repositoryCloneURLs(for repository: RepositorySummary) -> RepositoryCloneURLs {
16    let owner = repository.owner.canonicalName
17    let name = repository.name
18
19    switch repository.service {
20    case .git:
21        return RepositoryCloneURLs(
22            readOnly: "https://git.sr.ht/\(owner)/\(name)",
23            readWrite: "git@git.sr.ht:\(owner)/\(name)"
24        )
25    case .hg:
26        return RepositoryCloneURLs(
27            readOnly: "https://hg.sr.ht/\(owner)/\(name)",
28            readWrite: "ssh://hg@hg.sr.ht/\(owner)/\(name)"
29        )
30    default:
31        return RepositoryCloneURLs(
32            readOnly: "https://\(repository.service.rawValue).sr.ht/\(owner)/\(name)",
33            readWrite: ""
34        )
35    }
36}
37
38func repositoryVisibilityLabel(_ visibility: Visibility) -> String {
39    switch visibility {
40    case .public:
41        return "Public"
42    case .unlisted:
43        return "Unlisted"
44    case .private:
45        return "Private"
46    }
47}
48
49struct SummaryMetadataRow: View {
50    let icon: String
51    let title: String
52    var subtitle: String? = nil
53
54    var body: some View {
55        HStack(alignment: .top, spacing: 10) {
56            Image(systemName: icon)
57                .foregroundStyle(.secondary)
58                .frame(width: 18)
59
60            VStack(alignment: .leading, spacing: 2) {
61                Text(title)
62                if let subtitle, !subtitle.isEmpty {
63                    Text(subtitle)
64                        .font(.subheadline)
65                        .foregroundStyle(.secondary)
66                }
67            }
68        }
69    }
70}
71
72struct SummaryDetailRow: View {
73    let label: String
74    let value: String
75    var monospace: Bool = false
76
77    var body: some View {
78        VStack(alignment: .leading, spacing: 4) {
79            Text(label)
80                .font(.caption)
81                .foregroundStyle(.secondary)
82            Text(value)
83                .font(monospace ? .system(.body, design: .monospaced) : .body)
84                .textSelection(.enabled)
85        }
86    }
87}