Commit 6887325f24

6887325f24a4bd1a261c68f0adce77cf86290a02

parent: 29b32e9056

Verified · cmc

cmc <hello@cleberg.net> · 2026-09-22 23:23 UTC

admin: read the admin flag on the My Profile tab, not in the toolbar

AccountMenu's label can render as a native bar button, which iOS never
runs a .task on, so the admin read could silently never fire. Read
whoami once on ProfileView's .task on the My Profile tab instead and
pass the result into AccountMenu as a plain property.

Layout: unified · split

gitbay/ContentView.swift +9 −1
@@ -10,6 +10,10 @@ struct ContentView: View {
1010 @State private var selectedTab = Tabs.dashboard
1111 @State private var dashboardPath = NavigationPath()
1212
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
1317 /// Which account `dashboardPath`'s routes were resolved against.
1418 ///
1519 /// `.id(account.id)` sits on the `TabView`, not on `ContentView`, so
@@ -50,7 +54,11 @@ struct ContentView: View {
5054 NavigationStack {
5155 ProfileView(client: client, name: account.username,
5256 title: "My Profile")
53 .toolbar { AccountMenu() }
57 .toolbar { AccountMenu(isAdmin: isAdmin) }
58 .task {
59 isAdmin = false
60 isAdmin = await AdminCheck.isAdmin(client)
61 }
5462 .navigationDestinations(client: client)
5563 }
5664 }
gitbay/Views/Repos/RepoListView.swift +3 −10
@@ -254,9 +254,9 @@ struct AccountMenu: ToolbarContent {
254254
255255 @Environment(SessionStore.self) private var session
256256
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
260260
261261 var body: some ToolbarContent {
262262 ToolbarItem(placement: .topBarTrailing) {
@@ -296,13 +296,6 @@ struct AccountMenu: ToolbarContent {
296296 }
297297 } label: {
298298 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 }
306299 }
307300 .accessibilityIdentifier("account-menu")
308301 }