import SwiftUI /// A user or organization: `profile show` plus their reachable repos. struct ProfileView: View { @State private var model: ProfileViewModel init(client: GitbayClient, name: String) { _model = State(initialValue: ProfileViewModel(client: client, name: name)) } var body: some View { List { if let profile = model.state.value { Section { VStack(alignment: .leading, spacing: 6) { HStack(spacing: 8) { Image(systemName: profile.kind == "org" ? "building.2" : "person.crop.circle") .font(.title2) .foregroundStyle(.secondary) Text(profile.name) .font(.title3.weight(.semibold)) Text(profile.kind) .font(.caption2) .padding(.horizontal, 6) .padding(.vertical, 1) .background(.quaternary, in: Capsule()) } if let description = profile.description, !description.isEmpty { Text(description) .font(.subheadline) .foregroundStyle(.secondary) } if let website = profile.website, let url = URL(string: website) { Link(website, destination: url) .font(.caption) .lineLimit(1) } } .padding(.vertical, 4) } if profile.kind == "org" { Section { NavigationLink(value: OrgRoute.org(profile.name)) { Label("Members & Teams", systemImage: "person.3") } } } if !model.repos.isEmpty { Section("Repositories") { ForEach(model.repos) { repo in NavigationLink(value: RepoRoute.repo(repo.path)) { VStack(alignment: .leading, spacing: 2) { Text(repo.name) .font(.subheadline.weight(.medium)) if let description = repo.description, !description.isEmpty { Text(description) .font(.caption) .foregroundStyle(.secondary) .lineLimit(1) } } } } } } } } .overlay { LoadStateOverlay(state: model.state) } .navigationTitle(model.name) .navigationBarTitleDisplayMode(.inline) .task { await model.load() } .refreshable { await model.load() } } }