summaryrefslogtreecommitdiff
path: root/Hutch/Views/More/MoreView.swift
blob: eda918f27b71877e1dbf32c2e7f943d156fd9572 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import SwiftUI

struct MoreView: View {
    @Environment(AppState.self) private var appState

    private let unsupportedLinks: [(title: String, url: URL)] = [
        ("chat.sr.ht", SRHTWebURL.chat)
    ]

    @State private var viewModel: MoreViewModel?
    @State private var showAccountSwitcher = false

    var body: some View {
        List {
            Section("Search") {
                NavigationLink(value: MoreRoute.lookup(query: nil)) {
                    Label("Look Up", systemImage: "magnifyingglass")
                }
                .themedRow()
            }

            Section("Activity") {
                NavigationLink(value: MoreRoute.activity) {
                    Label("Ticket Activity", systemImage: "bell.badge")
                }
                .themedRow()
            }

            Section("Other Services") {
                NavigationLink(value: MoreRoute.projects) {
                    Label("Projects", systemImage: "square.stack.3d.up")
                }
                .themedRow()

                NavigationLink(value: MoreRoute.lists) {
                    Label("Mailing Lists", systemImage: "list.bullet.rectangle")
                }
                .themedRow()

                NavigationLink(value: MoreRoute.manPageBrowser) {
                    Label("Man Pages", systemImage: "book")
                }
                .themedRow()

                NavigationLink(value: MoreRoute.pastes) {
                    Label("Pastes", systemImage: "doc.on.clipboard")
                }
                .themedRow()

                NavigationLink(value: MoreRoute.systemStatus) {
                    SystemStatusSummaryRow(
                        snapshot: viewModel?.systemStatusSnapshot,
                        isLoading: viewModel?.isLoadingSystemStatus ?? true,
                        errorMessage: viewModel?.systemStatusErrorMessage,
                        isShowingStaleData: viewModel?.isShowingStaleSystemStatus ?? false
                    )
                }
                .themedRow()
            }

            Section("Meta") {
                NavigationLink(value: MoreRoute.profile) {
                    Label("Profile", systemImage: "person.text.rectangle")
                }
                .themedRow()

                NavigationLink(value: MoreRoute.settings) {
                    Label("Settings", systemImage: "gear")
                }
                .themedRow()

                NavigationLink(value: MoreRoute.about) {
                    Label("About Hutch", systemImage: "info.circle")
                }
                .themedRow()
            }

            Section {
                ForEach(unsupportedLinks, id: \.title) { item in
                    Link(destination: item.url) {
                        Label(item.title, systemImage: "safari")
                    }
                }
                .themedRow()
            } header: {
                Text("External Links")
            } footer: {
                Text("These SourceHut services are not supported in-app, as the SourceHut API does not support them, and will open in your browser.")
            }
        }
        .themedList()
        .navigationTitle("More")
        .refreshable {
            await ensureViewModel().loadSystemStatus(forceRefresh: true)
        }
        .task {
            await ensureViewModel().loadIfNeeded()
        }
        .toolbar {
            ToolbarItem(placement: .topBarTrailing) {
                Button {
                    showAccountSwitcher = true
                } label: {
                    Image(systemName: "person.crop.circle.badge.plus")
                }
            }
        }
        .sheet(isPresented: $showAccountSwitcher) {
            AccountSwitcherView()
        }
    }

    @MainActor
    private func ensureViewModel() -> MoreViewModel {
        if let viewModel {
            return viewModel
        }

        let newViewModel = MoreViewModel(repository: appState.systemStatusRepository)
        viewModel = newViewModel
        return newViewModel
    }
}