Commit 6887325f24
Verified · cmc
Layout: unified · split
gitbay/ContentView.swift +9 −1
| @@ -10,6 +10,10 @@ struct ContentView: View { | ||
| 10 | 10 | @State private var selectedTab = Tabs.dashboard |
| 11 | 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 | 17 | /// Which account `dashboardPath`'s routes were resolved against. |
| 14 | 18 | /// |
| 15 | 19 | /// `.id(account.id)` sits on the `TabView`, not on `ContentView`, so |
| @@ -50,7 +54,11 @@ struct ContentView: View { | ||
| 50 | 54 | NavigationStack { |
| 51 | 55 | ProfileView(client: client, name: account.username, |
| 52 | 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 | 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 | 255 | @Environment(SessionStore.self) private var session |
| 256 | 256 | |
| 257 | /// Read from `whoami` when the menu appears and on an account switch. | |
| 258 | /// The menu has no model; this is the one read that reaches it. | |
| 259 | @State private var isAdmin = false | |
| 257 | /// Whether the signed-in account is an instance admin, read from | |
| 258 | /// `whoami` on the My Profile tab and passed in. | |
| 259 | let isAdmin: Bool | |
| 260 | 260 | |
| 261 | 261 | var body: some ToolbarContent { |
| 262 | 262 | ToolbarItem(placement: .topBarTrailing) { |
| @@ -296,13 +296,6 @@ struct AccountMenu: ToolbarContent { | ||
| 296 | 296 | } |
| 297 | 297 | } label: { |
| 298 | 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 | 300 | .accessibilityIdentifier("account-menu") |
| 308 | 301 | } |