diff options
Diffstat (limited to 'Hutch/Views/Repositories/CommitLogView.swift')
| -rw-r--r-- | Hutch/Views/Repositories/CommitLogView.swift | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Hutch/Views/Repositories/CommitLogView.swift b/Hutch/Views/Repositories/CommitLogView.swift new file mode 100644 index 0000000..d63c5eb --- /dev/null +++ b/Hutch/Views/Repositories/CommitLogView.swift @@ -0,0 +1,59 @@ +import SwiftUI + +struct CommitLogView: View { + let viewModel: RepositoryDetailViewModel + + var body: some View { + List { + ForEach(viewModel.commits) { commit in + NavigationLink(value: commit) { + CommitRowView(commit: commit) + } + .task { + await viewModel.loadMoreCommitsIfNeeded(currentItem: commit) + } + } + + if viewModel.isLoadingMoreCommits { + HStack { + Spacer() + ProgressView() + Spacer() + } + .listRowSeparator(.hidden) + } + } + .listStyle(.plain) + .overlay { + if viewModel.isLoadingCommits, viewModel.commits.isEmpty { + SRHTLoadingStateView(message: "Loading commits…") + } else if let error = viewModel.error, viewModel.commits.isEmpty { + SRHTErrorStateView( + title: "Couldn't Load Commits", + message: error, + retryAction: { await viewModel.loadCommits() } + ) + } else if viewModel.commits.isEmpty { + ContentUnavailableView( + "No Commits", + systemImage: "clock.arrow.trianglehead.counterclockwise.rotate.90", + description: Text("This repository has no commit history.") + ) + } + } + .task { + if viewModel.commits.isEmpty { + await viewModel.loadCommits() + } + } + .refreshable { + await viewModel.loadCommits() + } + .navigationDestination(for: CommitSummary.self) { commit in + CommitDetailView( + commitSummary: commit, + repository: viewModel.repository + ) + } + } +} |
