Commit 6887325f24
Verified · cmc
Layout: unified · split
gitbay/ContentView.swift +9 −1
| @@ -10,6 +10,10 @@ struct ContentView: View { | |||
| 10 | @State private var selectedTab = Tabs.dashboard | 10 | @State private var selectedTab = Tabs.dashboard |
| 11 | @State private var dashboardPath = NavigationPath() | 11 | @State private var dashboardPath = NavigationPath() |
| 12 | 12 | ||
| 13 | /// whoami's admin flag, read on the My Profile tab, decides whether | ||
| 14 | /// the account menu offers Admin. | ||
| 15 | @State private var isAdmin = false | ||
| 16 | |||
| 13 | /// Which account `dashboardPath`'s routes were resolved against. | 17 | /// Which account `dashboardPath`'s routes were resolved against. |
| 14 | /// | 18 | /// |
| 15 | /// `.id(account.id)` sits on the `TabView`, not on `ContentView`, so | 19 | /// `.id(account.id)` sits on the `TabView`, not on `ContentView`, so |
| @@ -50,7 +54,11 @@ struct ContentView: View { | |||
| 50 | NavigationStack { | 54 | NavigationStack { |
| 51 | ProfileView(client: client, name: account.username, | 55 | ProfileView(client: client, name: account.username, |
| 52 | title: "My Profile") | 56 | title: "My Profile") |
| 53 | .toolbar { AccountMenu() } | 57 | .toolbar { AccountMenu(isAdmin: isAdmin) } |
| 58 | .task { | ||
| 59 | isAdmin = false | ||
| 60 | isAdmin = await AdminCheck.isAdmin(client) | ||
| 61 | } | ||
| 54 | .navigationDestinations(client: client) | 62 | .navigationDestinations(client: client) |
| 55 | } | 63 | } |
| 56 | } | 64 | } |
gitbay/Views/Repos/RepoListView.swift +3 −10
| @@ -254,9 +254,9 @@ struct AccountMenu: ToolbarContent { | |||
| 254 | 254 | ||
| 255 | @Environment(SessionStore.self) private var session | 255 | @Environment(SessionStore.self) private var session |
| 256 | 256 | ||
| 257 | /// Read from `whoami` when the menu appears and on an account switch. | 257 | /// Whether the signed-in account is an instance admin, read from |
| 258 | /// The menu has no model; this is the one read that reaches it. | 258 | /// `whoami` on the My Profile tab and passed in. |
| 259 | @State private var isAdmin = false | 259 | let isAdmin: Bool |
| 260 | 260 | ||
| 261 | var body: some ToolbarContent { | 261 | var body: some ToolbarContent { |
| 262 | ToolbarItem(placement: .topBarTrailing) { | 262 | ToolbarItem(placement: .topBarTrailing) { |
| @@ -296,13 +296,6 @@ struct AccountMenu: ToolbarContent { | |||
| 296 | } | 296 | } |
| 297 | } label: { | 297 | } label: { |
| 298 | Image(systemName: "person.crop.circle") | 298 | Image(systemName: "person.crop.circle") |
| 299 | // ToolbarContent takes no .task; the label is a view. | ||
| 300 | .task(id: session.current?.id) { | ||
| 301 | isAdmin = false | ||
| 302 | if let client = session.client { | ||
| 303 | isAdmin = await AdminCheck.isAdmin(client) | ||
| 304 | } | ||
| 305 | } | ||
| 306 | } | 299 | } |
| 307 | .accessibilityIdentifier("account-menu") | 300 | .accessibilityIdentifier("account-menu") |
| 308 | } | 301 | } |