treefmt: apply prettier
Pure `nix fmt` output from the commit before this one — no hand edits. 203 files: 52 md, 42 tsx, 32 js, 32 css, 21 ts, 13 html, 8 json, 3 mjs. Reproduce with `nix develop -c nix fmt` on the parent commit; the result should be byte-identical to this tree. None of the 13 `.prettierignore` entries appears here — verified by intersecting the changed-file list against the ignore file, with a control proving the intersection finds a match when one exists.
This commit is contained in:
parent
5d24bedd60
commit
39b95c2ede
203 changed files with 10090 additions and 6085 deletions
|
|
@ -21,8 +21,8 @@
|
|||
// second source of the domain — `/settings` and `/logout` are appended
|
||||
// client-side, both real authelia routes (mara confirmed `/settings` is
|
||||
// the real path after the plain domain-root link landed short of it).
|
||||
import { useEffect, useRef, useState } from 'preact/hooks';
|
||||
import './UserMenu.css';
|
||||
import { useEffect, useRef, useState } from "preact/hooks";
|
||||
import "./UserMenu.css";
|
||||
|
||||
interface WhoAmI {
|
||||
displayName: string | null;
|
||||
|
|
@ -39,18 +39,19 @@ interface ServiceLink {
|
|||
// not imported from there directly: that list is route accents, this is
|
||||
// a name→colour pick, different domains that happen to share a palette.
|
||||
const AVATAR_ACCENTS = [
|
||||
'var(--red)',
|
||||
'var(--yellow)',
|
||||
'var(--green)',
|
||||
'var(--cyan)',
|
||||
'var(--blue)',
|
||||
'var(--purple)',
|
||||
'var(--pink)',
|
||||
"var(--red)",
|
||||
"var(--yellow)",
|
||||
"var(--green)",
|
||||
"var(--cyan)",
|
||||
"var(--blue)",
|
||||
"var(--purple)",
|
||||
"var(--pink)",
|
||||
];
|
||||
|
||||
function pickAccent(seed: string): string {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < seed.length; i++) hash = (hash * 31 + seed.charCodeAt(i)) | 0;
|
||||
for (let i = 0; i < seed.length; i++)
|
||||
hash = (hash * 31 + seed.charCodeAt(i)) | 0;
|
||||
return AVATAR_ACCENTS[Math.abs(hash) % AVATAR_ACCENTS.length];
|
||||
}
|
||||
|
||||
|
|
@ -61,9 +62,11 @@ function pickAccent(seed: string): string {
|
|||
function parseWhoAmI(body: unknown): WhoAmI {
|
||||
const record = (body ?? {}) as Record<string, unknown>;
|
||||
const data = (record.data ?? record) as Record<string, unknown>;
|
||||
const displayName = typeof data.display_name === 'string' ? data.display_name : null;
|
||||
const displayName =
|
||||
typeof data.display_name === "string" ? data.display_name : null;
|
||||
const emails = Array.isArray(data.emails) ? data.emails : null;
|
||||
const email = emails && typeof emails[0] === 'string' ? (emails[0] as string) : null;
|
||||
const email =
|
||||
emails && typeof emails[0] === "string" ? (emails[0] as string) : null;
|
||||
return { displayName, email };
|
||||
}
|
||||
|
||||
|
|
@ -74,8 +77,10 @@ export function UserMenu() {
|
|||
const rootRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/whoami')
|
||||
.then((r) => (r.ok ? r.json() : Promise.reject(new Error(`http ${r.status}`))))
|
||||
fetch("/api/whoami")
|
||||
.then((r) =>
|
||||
r.ok ? r.json() : Promise.reject(new Error(`http ${r.status}`)),
|
||||
)
|
||||
.then((body) => setWho(parseWhoAmI(body)))
|
||||
.catch(() => setWho(null)); // cosmetic only — see file-top comment
|
||||
}, []);
|
||||
|
|
@ -83,10 +88,14 @@ export function UserMenu() {
|
|||
// Reuses `LinksMenu`'s own data source rather than a second endpoint —
|
||||
// see file-top comment.
|
||||
useEffect(() => {
|
||||
fetch('/api/links')
|
||||
.then((r) => (r.ok ? (r.json() as Promise<ServiceLink[]>) : Promise.reject(new Error(`http ${r.status}`))))
|
||||
fetch("/api/links")
|
||||
.then((r) =>
|
||||
r.ok
|
||||
? (r.json() as Promise<ServiceLink[]>)
|
||||
: Promise.reject(new Error(`http ${r.status}`)),
|
||||
)
|
||||
.then((links) => {
|
||||
const authelia = links.find((l) => l.label === 'Authelia');
|
||||
const authelia = links.find((l) => l.label === "Authelia");
|
||||
if (authelia) setAutheliaUrl(authelia.url);
|
||||
})
|
||||
.catch(() => {
|
||||
|
|
@ -99,27 +108,28 @@ export function UserMenu() {
|
|||
useEffect(() => {
|
||||
if (!open) return;
|
||||
function onPointerDown(e: MouseEvent) {
|
||||
if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpen(false);
|
||||
if (rootRef.current && !rootRef.current.contains(e.target as Node))
|
||||
setOpen(false);
|
||||
}
|
||||
function onKeyDown(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape') setOpen(false);
|
||||
if (e.key === "Escape") setOpen(false);
|
||||
}
|
||||
document.addEventListener('pointerdown', onPointerDown);
|
||||
document.addEventListener('keydown', onKeyDown);
|
||||
document.addEventListener("pointerdown", onPointerDown);
|
||||
document.addEventListener("keydown", onKeyDown);
|
||||
return () => {
|
||||
document.removeEventListener('pointerdown', onPointerDown);
|
||||
document.removeEventListener('keydown', onKeyDown);
|
||||
document.removeEventListener("pointerdown", onPointerDown);
|
||||
document.removeEventListener("keydown", onKeyDown);
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
const label = who?.displayName || who?.email || null;
|
||||
const initial = label ? label.trim().charAt(0).toUpperCase() : '?';
|
||||
const accent = pickAccent(label ?? 'operator');
|
||||
const initial = label ? label.trim().charAt(0).toUpperCase() : "?";
|
||||
const accent = pickAccent(label ?? "operator");
|
||||
// Trailing slash normalised off so `/logout` appends cleanly
|
||||
// regardless of whether the contributed link kept one (the `Authelia`
|
||||
// entry does — see `swarm-authelia.nix` — but this isn't the only
|
||||
// conceivable shape a future contributor's own URL could take).
|
||||
const base = autheliaUrl?.replace(/\/+$/, '') ?? null;
|
||||
const base = autheliaUrl?.replace(/\/+$/, "") ?? null;
|
||||
|
||||
return (
|
||||
<div class="user-menu" ref={rootRef}>
|
||||
|
|
@ -129,7 +139,7 @@ export function UserMenu() {
|
|||
style={{ background: accent }}
|
||||
aria-haspopup="true"
|
||||
aria-expanded={open}
|
||||
aria-label={label ? `signed in as ${label}` : 'account'}
|
||||
aria-label={label ? `signed in as ${label}` : "account"}
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
>
|
||||
{initial}
|
||||
|
|
@ -149,7 +159,12 @@ export function UserMenu() {
|
|||
>
|
||||
authelia settings
|
||||
</a>
|
||||
<a class="user-menu-item" href={`${base}/logout`} role="menuitem" onClick={() => setOpen(false)}>
|
||||
<a
|
||||
class="user-menu-item"
|
||||
href={`${base}/logout`}
|
||||
role="menuitem"
|
||||
onClick={() => setOpen(false)}
|
||||
>
|
||||
log out
|
||||
</a>
|
||||
</>
|
||||
|
|
|
|||
Loading…
Reference in a new issue