gitbay/Views/Admin/AdminView.swift
59 lines · 2302 bytes
1import SwiftUI
2
3/// The web's /admin page: the server build, a way to the accounts, and
4/// every worker queue's backlog in the web's order and words.
5struct AdminView: View {
6
7 @State private var model: AdminOverviewViewModel
8
9 init(client: GitbayClient) {
10 _model = State(initialValue: AdminOverviewViewModel(client: client))
11 }
12
13 var body: some View {
14 List {
15 if let overview = model.state.value {
16 Section {
17 NavigationLink(value: RepoRoute.adminUsers) {
18 Label("Accounts", systemImage: "person.2")
19 }
20 .accessibilityIdentifier("admin-accounts")
21 } footer: {
22 if let commit = overview.commit {
23 Text("Server build \(commit).")
24 }
25 }
26 ForEach(overview.sections) { section in
27 Section {
28 if section.rows.isEmpty {
29 Text(section.empty)
30 .font(.gbSans(.subheadline))
31 .foregroundStyle(.secondary)
32 } else {
33 ForEach(section.rows) { line in
34 VStack(alignment: .leading, spacing: 2) {
35 Text(line.title)
36 .font(.gbSans(.subheadline).weight(.medium))
37 Text(line.detail)
38 .font(.gbSans(.caption))
39 .foregroundStyle(.secondary)
40 }
41 }
42 }
43 } header: {
44 Text("\(section.heading) \(section.count)")
45 } footer: {
46 if let summary = section.summary {
47 Text(summary)
48 }
49 }
50 }
51 }
52 }
53 .overlay { LoadStateOverlay(state: model.state) }
54 .navigationTitle("Admin")
55 .navigationBarTitleDisplayMode(.inline)
56 .task { await model.load() }
57 .refreshable { await model.load() }
58 }
59}