AthleteView: listen for bincio:me event so owner tabs appear without hard refresh

In multi-user instances /api/me is async and usually hasn't returned by the
time onMount runs, leaving isOwner=false. Subscribe to the bincio:me event
(fired by Base.astro when /api/me resolves) so the reactive TABS filter
re-evaluates and Explore / Nerd Corner appear without needing Cmd+Shift+R.
This commit is contained in:
Davide Scaini
2026-05-15 01:15:24 +02:00
parent 4ea2292e2b
commit c12f5336f5
+10 -1
View File
@@ -84,7 +84,16 @@
}
onMount(async () => {
isOwner = (window as any).__bincioMe === handle;
const w = window as any;
if (w.__bincioMe !== undefined) {
isOwner = w.__bincioMe === handle;
} else {
// Multi-user: __bincioMe is set asynchronously by /api/me in Base.astro.
// Listen for the event so owner-only tabs appear without a hard refresh.
window.addEventListener('bincio:me', (e: Event) => {
isOwner = (e as CustomEvent<string>).detail === handle;
}, { once: true });
}
const TABS: Tab[] = ['power', 'records', 'segments', 'profile', 'explore', 'nerd'];
const rawTab = new URLSearchParams(window.location.search).get('tab');
const resolved = TABS.includes(rawTab as Tab) ? (rawTab as Tab) : 'power';