Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 10s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 10s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m12s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 3m4s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 8m17s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 10m36s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Version every /api route to /api/v1 (251 controller routes + ~24 Location
headers + the scanner callback URL + the Startup request-log literal),
uniform across the machine API, auth, scanner and scripted-build surfaces.
Add ApiVersionRewriteMiddleware: a legacy unversioned /api/* request is
rewritten (NOT redirected) to /api/v1/* in-pipeline — method, body, auth
headers and query survive — carrying RFC 8594 Deprecation/Sunset headers,
so curl / the future MCP server / bookmarks keep working. An already-
versioned path passes through; a future /api/v2 is never forced to v1.
Standardize the route convention (leading-slash absolute route per method,
no class-[Route] — except the two Scanner/Scripted controllers whose ~all
actions share a parametrized {id} prefix), enforced by ApiRouteVersioningTests
(^/api/v\d+/ over the whole Controllers.Api surface; browser-nav
/auth/oidc/login is out of scope).
Regenerate v1.json (160 paths, all /api/v1)/endpoint-index/v1.d.ts; sweep 945
SPA request literals + the test mocks (regex + positional URL parsers). /api/v1
is additive-only after freeze; the legacy-rewrite shim sunsets in ~2 releases
(owner decision) with removal tracked as a Phase-3 follow-up.
Docs: decisions.md 2026-07-13, api-conventions §1/§9, rest-api/spa-conventions/
blazor-route-parity/e2e-local/domain-model.
fixes #286
refs #197
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
96 lines
2.8 KiB
TypeScript
96 lines
2.8 KiB
TypeScript
import { useContext, useEffect, useRef, useState, type KeyboardEvent } from 'react';
|
|
import { ChevronDown, LogOut, UserRound } from 'lucide-react';
|
|
import { logout } from './api';
|
|
import { AuthContext } from './AuthGate';
|
|
import { canLeaveCurrentScreen } from './navigationGuard';
|
|
|
|
// TopBar sign-out control (#295). Shows the authenticated username and a Sign out action: it consults the
|
|
// unsaved-changes guard first (so a dirty draft isn't lost), POSTs `/api/v1/auth/logout` (the client adds the
|
|
// required X-CSRF header), and on 204 flips the boot gate back to the login screen via AuthContext.signOut.
|
|
export function UserMenu() {
|
|
const { username, signOut } = useContext(AuthContext);
|
|
const [open, setOpen] = useState(false);
|
|
const [signingOut, setSigningOut] = useState(false);
|
|
const menuRef = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
if (open) {
|
|
menuRef.current?.focus();
|
|
}
|
|
}, [open]);
|
|
|
|
const onMenuKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
if (event.key === 'Escape') {
|
|
setOpen(false);
|
|
}
|
|
};
|
|
|
|
const onSignOut = () => {
|
|
if (signingOut || !canLeaveCurrentScreen()) {
|
|
return;
|
|
}
|
|
|
|
setSigningOut(true);
|
|
logout()
|
|
.then(() => {
|
|
setOpen(false);
|
|
signOut();
|
|
})
|
|
.catch(() => {
|
|
// A failed logout leaves the session intact; drop the busy state so the user can retry.
|
|
setSigningOut(false);
|
|
});
|
|
};
|
|
|
|
const label = username ?? 'Account';
|
|
|
|
return (
|
|
<div className="ctv-connect">
|
|
<button
|
|
aria-expanded={open}
|
|
className="ctv-connect-button"
|
|
onClick={() => setOpen((current) => !current)}
|
|
type="button"
|
|
>
|
|
<UserRound aria-hidden="true" size={15} />
|
|
{label}
|
|
<ChevronDown aria-hidden="true" size={13} />
|
|
</button>
|
|
|
|
{open && (
|
|
<>
|
|
<button
|
|
aria-label="Close account menu"
|
|
className="ctv-connect-dismiss"
|
|
onClick={() => setOpen(false)}
|
|
type="button"
|
|
/>
|
|
<div
|
|
aria-label="Account"
|
|
className="ctv-connect-menu"
|
|
onKeyDown={onMenuKeyDown}
|
|
ref={menuRef}
|
|
role="dialog"
|
|
tabIndex={-1}
|
|
>
|
|
<div className="ctv-connect-header">
|
|
<strong>{label}</strong>
|
|
<span>Signed in</span>
|
|
</div>
|
|
<button
|
|
className="ctv-auth-banner-link ctv-press"
|
|
disabled={signingOut}
|
|
onClick={onSignOut}
|
|
style={{ alignItems: 'center', display: 'inline-flex', gap: 6, margin: '4px 0 0' }}
|
|
type="button"
|
|
>
|
|
<LogOut aria-hidden="true" size={14} />
|
|
Sign out
|
|
</button>
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|