From 32ad6cab8d58d99ebd8a28e8fa6e6f4e587cb1e5 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Tue, 17 Mar 2026 23:19:43 -0500 Subject: v1.0 --- Hutch/Views/Repositories/ArtifactsView.swift | 73 ++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Hutch/Views/Repositories/ArtifactsView.swift (limited to 'Hutch/Views/Repositories/ArtifactsView.swift') diff --git a/Hutch/Views/Repositories/ArtifactsView.swift b/Hutch/Views/Repositories/ArtifactsView.swift new file mode 100644 index 0000000..ef3b972 --- /dev/null +++ b/Hutch/Views/Repositories/ArtifactsView.swift @@ -0,0 +1,73 @@ +import SwiftUI + +struct ArtifactsView: View { + let viewModel: RepositoryDetailViewModel + @Environment(\.openURL) private var openURL + + var body: some View { + List { + ForEach(viewModel.referenceArtifacts) { refArtifacts in + Section(refArtifacts.name) { + ForEach(refArtifacts.artifacts) { artifact in + ArtifactRow(artifact: artifact) { + openURL(artifact.url) + } + } + } + } + } + .listStyle(.insetGrouped) + .overlay { + if viewModel.isLoadingArtifacts, viewModel.referenceArtifacts.isEmpty { + SRHTLoadingStateView(message: "Loading artifacts…") + } else if let error = viewModel.error, viewModel.referenceArtifacts.isEmpty { + SRHTErrorStateView( + title: "Couldn't Load Artifacts", + message: error, + retryAction: { await viewModel.loadArtifacts() } + ) + } else if viewModel.referenceArtifacts.isEmpty { + ContentUnavailableView( + "No Artifacts", + systemImage: "archivebox", + description: Text("This repository has no release artifacts.") + ) + } + } + .task { + if viewModel.referenceArtifacts.isEmpty { + await viewModel.loadArtifacts() + } + } + .refreshable { + await viewModel.loadArtifacts() + } + } +} + +private struct ArtifactRow: View { + let artifact: ArtifactInfo + let onDownload: () -> Void + + var body: some View { + HStack { + VStack(alignment: .leading, spacing: 4) { + Text(artifact.filename) + .font(.subheadline) + + Text(artifact.size.formattedByteCount) + .font(.caption) + .foregroundStyle(.secondary) + } + + Spacer() + + Button { + onDownload() + } label: { + Image(systemName: "arrow.down.circle") + .imageScale(.large) + } + } + } +} -- cgit v1.2.3