84 lines
2.9 KiB
Swift
84 lines
2.9 KiB
Swift
import HelderCore
|
|
import SwiftUI
|
|
|
|
/// The bottom strip's right end on a wide window: the last commits of the current branch, read-only.
|
|
struct GitCommitsPanel: View {
|
|
let store: SourceControlStore
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
header
|
|
if !store.state.isRepository {
|
|
placeholder("— no repository")
|
|
} else if store.recentCommits.isEmpty {
|
|
placeholder("no commits yet")
|
|
} else {
|
|
ScrollView {
|
|
TimelineView(.periodic(from: .now, by: 30)) { context in
|
|
LazyVStack(alignment: .leading, spacing: 0) {
|
|
ForEach(store.recentCommits, id: \.hash) { commit in
|
|
CommitRow(commit: commit, now: context.date)
|
|
}
|
|
}
|
|
.padding(.bottom, 12)
|
|
}
|
|
.background(OverlayScrollers())
|
|
}
|
|
.scrollIndicators(.automatic)
|
|
}
|
|
Spacer(minLength: 0)
|
|
}
|
|
.clipped()
|
|
}
|
|
|
|
private var header: some View {
|
|
HStack(spacing: 12) {
|
|
Text("[ commits ]").typeRole(Typography.panelLabel).foregroundStyle(Palette.text4).fixedSize()
|
|
Spacer(minLength: 0)
|
|
if store.state.isRepository {
|
|
Text(store.state.branch)
|
|
.typeRole(Typography.path)
|
|
.foregroundStyle(Palette.textMuted)
|
|
.lineLimit(1)
|
|
.truncationMode(.middle)
|
|
}
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.frame(height: GitMetrics.stripHeader)
|
|
}
|
|
|
|
private func placeholder(_ text: String) -> some View {
|
|
Text(text)
|
|
.typeRole(Typography.path)
|
|
.foregroundStyle(Palette.text4)
|
|
.padding(.horizontal, 16)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
}
|
|
|
|
private struct CommitRow: View {
|
|
let commit: GitCommitSummary
|
|
let now: Date
|
|
|
|
var body: some View {
|
|
HStack(spacing: 10) {
|
|
Text(commit.hash).typeRole(Typography.gitStats).foregroundStyle(Palette.amber).fixedSize()
|
|
Text(commit.subject)
|
|
.typeRole(Typography.path)
|
|
.foregroundStyle(Palette.text2)
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
HStack(spacing: 0) {
|
|
Text(commit.author).lineLimit(1).truncationMode(.tail).frame(maxWidth: 140, alignment: .trailing)
|
|
Text(" · \(RelativeTime.text(commit.date, now: now))").fixedSize()
|
|
}
|
|
.typeRole(Typography.meta)
|
|
.foregroundStyle(Palette.text4)
|
|
.layoutPriority(1)
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.frame(height: GitMetrics.branchRow)
|
|
}
|
|
}
|