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