import SwiftUI /// Branches and tags. Tapping one browses the repository at that ref. struct RefsView: View { @State private var model: RefsViewModel init(client: GitbayClient, repo: String) { _model = State(initialValue: RefsViewModel(client: client, repoPath: repo)) } var body: some View { List { if !model.branches.isEmpty { Section("Branches") { ForEach(model.branches) { ref in NavigationLink(value: RepoRoute.tree( repo: model.repoPath, directory: "", ref: ref.name )) { RefRow(ref: ref, isDefault: ref.name == model.defaultBranch) } } } } if !model.tags.isEmpty { Section("Tags") { ForEach(model.tags) { ref in NavigationLink(value: RepoRoute.tree( repo: model.repoPath, directory: "", ref: ref.name )) { RefRow(ref: ref, isDefault: false) } } } } } .overlay { LoadStateOverlay( state: model.state, isEmpty: model.branches.isEmpty && model.tags.isEmpty ) } .searchable(text: Bindable(model).searchText, prompt: "Filter refs") .navigationTitle("Branches & Tags") .navigationBarTitleDisplayMode(.inline) .task { await model.load() } .refreshable { await model.load() } } } private struct RefRow: View { let ref: RepoRef let isDefault: Bool var body: some View { HStack(spacing: 8) { Text(ref.name) .font(.gbSans(.subheadline)) .lineLimit(1) if isDefault { GBChip("default", .gbAccent) } Spacer() Text(String(ref.sha.prefix(10))) .font(.gbMono(.caption2)) .foregroundStyle(.tertiary) } } }