1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
import SwiftUI
struct RepositoryCloneURLs {
let readOnly: String
let readWrite: String
}
func repositoryCloneURLs(for repository: RepositorySummary) -> RepositoryCloneURLs {
let owner = repository.owner.canonicalName
let name = repository.name
switch repository.service {
case .git:
return RepositoryCloneURLs(
readOnly: "https://git.sr.ht/\(owner)/\(name)",
readWrite: "[email protected]:\(owner)/\(name)"
)
case .hg:
return RepositoryCloneURLs(
readOnly: "https://hg.sr.ht/\(owner)/\(name)",
readWrite: "ssh://[email protected]/\(owner)/\(name)"
)
default:
return RepositoryCloneURLs(
readOnly: "https://\(repository.service.rawValue).sr.ht/\(owner)/\(name)",
readWrite: ""
)
}
}
func repositoryVisibilityLabel(_ visibility: Visibility) -> String {
switch visibility {
case .public:
return "Public"
case .unlisted:
return "Unlisted"
case .private:
return "Private"
}
}
struct RepositorySummaryCard<Content: View>: View {
let title: String
@ViewBuilder let content: Content
init(_ title: String, @ViewBuilder content: () -> Content) {
self.title = title
self.content = content()
}
var body: some View {
VStack(alignment: .leading, spacing: 12) {
Text(title)
.font(.caption.weight(.semibold))
.foregroundStyle(.secondary)
.textCase(.uppercase)
content
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
.background(.thinMaterial, in: RoundedRectangle(cornerRadius: 16, style: .continuous))
}
}
struct RepositorySummaryField: View {
let label: String
let value: String
var monospace: Bool = false
var body: some View {
VStack(alignment: .leading, spacing: 4) {
Text(label)
.font(.caption)
.foregroundStyle(.secondary)
Text(value)
.font(monospace ? .system(.body, design: .monospaced) : .body)
.textSelection(.enabled)
}
}
}
struct RepositorySummaryListRow: View {
let label: String
let values: [String]
var body: some View {
VStack(alignment: .leading, spacing: 4) {
Text(label)
.font(.caption)
.foregroundStyle(.secondary)
if values.isEmpty {
Text("None")
.foregroundStyle(.tertiary)
} else {
Text(values.joined(separator: ", "))
}
}
}
}
|