Replace admin Back button with UserMenu

Remove the Back button and its sessionStorage return-URL stash
logic. Add UserMenu to the right side of the admin topbar,
providing consistent navigation to all surfaces and eliminating
the infinite-loop problem (Back → / → admin → Back → ...).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-27 13:34:11 +00:00
parent 3760fb1d96
commit 497251cf59

View File

@@ -15,6 +15,7 @@ const { render } = preact;
import { ToastContainer } from '../../primitives/toast.js';
import { DialogStack } from '../../shell/dialog-stack.js';
import { UserMenu } from '../../shell/user-menu.js';
// ── Category → Section mapping ──────────────
const ADMIN_SECTIONS = {
@@ -121,26 +122,6 @@ function AdminSurface() {
}
}, [section]);
// Back button with return URL stash
useEffect(() => {
const RETURN_KEY = 'sb_admin_return';
if (!sessionStorage.getItem(RETURN_KEY)) {
const ref = document.referrer;
if (ref && ref.startsWith(location.origin) && !ref.includes('/admin')) {
sessionStorage.setItem(RETURN_KEY, ref);
} else {
sessionStorage.setItem(RETURN_KEY, location.origin + BASE + '/');
}
}
}, []);
const backClick = useCallback((e) => {
e.preventDefault();
const RETURN_KEY = 'sb_admin_return';
const returnURL = sessionStorage.getItem(RETURN_KEY);
sessionStorage.removeItem(RETURN_KEY);
location.href = returnURL || BASE + '/';
}, []);
const navClick = useCallback((e) => {
e.preventDefault();
@@ -155,15 +136,6 @@ function AdminSurface() {
<div class="surface-admin">
${/* Top Bar */``}
<div class="admin-topbar">
<a href="${BASE}/" class="admin-topbar-back" onClick=${backClick}>
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="19" y1="12" x2="5" y2="12"/>
<polyline points="12 19 5 12 12 5"/>
</svg>
Back
</a>
<div class="admin-topbar-sep"></div>
<span class="admin-topbar-title">
<img src="${BASE}/favicon.svg" alt="" width="18" height="18" style="vertical-align:-3px;" />
Administration
@@ -179,6 +151,10 @@ function AdminSurface() {
</a>
`)}
</div>
<div style="margin-left:auto;">
<${UserMenu} placement="down-right" />
</div>
</div>
<div class="admin-body">