krz/hutch

an ios client for sourcehut

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

v3.0.0: Hutch/Views/Repositories/CommitRowView.swift · raw

 1import SwiftUI
 2
 3struct CommitRowView: View {
 4    @Environment(AppState.self) private var appState
 5    @Environment(\.openURL) private var openURL
 6
 7    let commit: CommitSummary
 8    let repository: RepositorySummary
 9
10    var body: some View {
11        VStack(alignment: .leading, spacing: 4) {
12            Text(commit.title)
13                .font(.subheadline)
14                .lineLimit(1)
15
16            HStack(spacing: 8) {
17                Text(commit.shortId)
18                    .font(.caption.monospaced())
19                    .foregroundStyle(.secondary)
20
21                Text(commit.author.name)
22                    .font(.caption)
23                    .foregroundStyle(.secondary)
24
25                Spacer()
26
27                Text(commit.author.time.relativeDescription)
28                    .font(.caption)
29                    .foregroundStyle(.tertiary)
30            }
31        }
32        .padding(.vertical, 2)
33        .contextMenu {
34            if let url = SRHTWebURL.commit(repository: repository, commitId: commit.id) {
35                Button {
36                    openURL(url)
37                } label: {
38                    Label("Open in Browser", systemImage: "safari")
39                }
40            }
41
42            Button {
43                appState.copyToPasteboard(commit.id, label: "commit SHA")
44            } label: {
45                Label("Copy Full SHA", systemImage: "doc.on.doc")
46            }
47
48            Button {
49                appState.copyToPasteboard(commit.shortId, label: "short commit SHA")
50            } label: {
51                Label("Copy Short SHA", systemImage: "doc.on.doc.fill")
52            }
53        }
54    }
55}