gitbay/Views/Discovery/ExploreView.swift
63 lines · 2404 bytes
1import SwiftUI
2
3/// What this instance hosts. `repo search` needs a query; this is the
4/// listing you read when you do not know a name yet.
5struct ExploreView: View {
6
7 @State private var list: PagedListModel<PublicRepo>
8
9 init(client: GitbayClient) {
10 _list = State(initialValue: PagedListModel(
11 client: client,
12 argv: ["explore"],
13 emptyMessage: "This instance hosts no public repositories."
14 ))
15 }
16
17 var body: some View {
18 List {
19 ForEach(list.state.value ?? []) { repo in
20 NavigationLink(value: RepoRoute.repo(repo.path)) {
21 VStack(alignment: .leading, spacing: 4) {
22 HStack(spacing: 6) {
23 Text(repo.owner + "/")
24 .foregroundStyle(.secondary)
25 + Text(repo.name)
26 .fontWeight(.medium)
27 if repo.isArchived {
28 GBChip("archived", .secondary)
29 }
30 }
31 .font(.gbSans(.subheadline))
32 .lineLimit(1)
33
34 if let description = repo.description, !description.isEmpty {
35 Text(description)
36 .font(.gbSans(.caption))
37 .foregroundStyle(.secondary)
38 .lineLimit(2)
39 }
40 if let topics = repo.topics, !topics.isEmpty {
41 ScrollView(.horizontal, showsIndicators: false) {
42 HStack(spacing: 6) {
43 ForEach(topics, id: \.self) { topic in
44 GBChip(topic, .gbAccent)
45 }
46 }
47 }
48 }
49 }
50 .padding(.vertical, 2)
51 }
52 }
53 PageFooter(list: list)
54 }
55 .overlay { LoadStateOverlay(state: list.state) }
56 .navigationTitle("Explore")
57 .toolbar { AccountMenu() }
58 .task {
59 if list.state.value == nil { await list.reload() }
60 }
61 .refreshable { await list.reload() }
62 }
63}