From 7f8afdcdbb84dfe37f2fa88a8f788f176cce92a4 Mon Sep 17 00:00:00 2001 From: Matthew Daubney Date: Tue, 13 Oct 2026 22:12:02 +0100 Subject: [PATCH] Move account pages into a menu under the user's name (SCR-3) The header's name link and Sign out become a button opening a menu of Profile, Sharing, Apps, Sessions, Import and Sign out; the main nav keeps Overview, History and Album art. Keyboard and screen-reader friendly. The Profile page now refetches the user after a failed change instead of showing stale state. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 2 +- docs/admin-guide.md | 2 +- docs/user-guide.md | 11 ++-- frontend/css/style.css | 90 +++++++++++++++++++++++++++---- frontend/js/account.js | 2 + frontend/js/layout.js | 119 +++++++++++++++++++++++++++++++++++------ 6 files changed, 193 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 0739ecb..2c58c70 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ cp .env.example .env # then set SECRET_KEY and POSTGRES_PAS docker compose up -d # db, api (:5050), worker, ui (:8080) ``` -Open http://localhost:8080, create an account, then go to **Apps** and create an app for +Open http://localhost:8080, create an account, then open **Apps** from the account menu (top right) and create an app for a player. See [docs/admin-guide.md](docs/admin-guide.md) for the published images, full configuration reference and production notes. diff --git a/docs/admin-guide.md b/docs/admin-guide.md index 2135ad7..2f015d1 100644 --- a/docs/admin-guide.md +++ b/docs/admin-guide.md @@ -35,7 +35,7 @@ cp .env.example .env # then set SECRET_KEY and POSTGRES_PASSWORD SCROBBLER_IMAGE_TAG=main docker compose up -d --no-build # or drop --no-build to build locally ``` -Open `http://localhost:8080`, create an account, then go to **Apps** and create an app +Open `http://localhost:8080`, create an account, then open **Apps** from the account menu (top right) and create an app for each player. Add `--profile monitoring` for Prometheus and Grafana. Published images: `pkgs.daubney.dev/scrobbler/scrobbler-api` and diff --git a/docs/user-guide.md b/docs/user-guide.md index 7d20ba3..a07fca1 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -6,7 +6,8 @@ instance rather than using one, see the [admin guide](admin-guide.md) instead. ## Getting started -Register in the web UI, then go to **Apps** and create one app per player or scrobbler +Register in the web UI, then open the account menu at the top right (your picture and +name), go to **Apps** and create one app per player or scrobbler client you use — each gets its own API key and shared secret, and can be revoked on its own from the **Sessions** page without affecting the others. If a friend runs your instance, ask them for its address; that's the only thing you need from them to get @@ -47,7 +48,7 @@ scrobbler is one example; look for a plugin or a different player with 2.0 suppo ## Importing history -Open **Import** in the web UI: +Open **Import** from the account menu: - **An export file**: - CSV from [lastfm-to-csv](https://benjaminbenben.com/lastfm-to-csv/), no header row, @@ -67,8 +68,8 @@ skipped, so importing the same export again, or importing overlapping exports, i ## Your profile image -Click your name in the page header to open **Profile**, where you can give yourself a -picture, shown next to your name. Upload a JPEG, PNG or WebP image, or remove it again. +Open the account menu at the top right (your picture and name) and choose **Profile**, where +you can give yourself a picture, shown next to your name. Upload a JPEG, PNG or WebP image, or remove it again. If your instance's admin has allowed it, you can also **use your Gravatar**. The server asks Gravatar for the picture linked to your account email, sending it a hash of that @@ -84,7 +85,7 @@ removal can take a while to show up everywhere. ## Sharing on the fediverse Only available if your instance's admin has turned this on — ask them, or check whether -**Sharing** appears in the navigation. Turn it on there, and you're findable as +**Sharing** appears in the account menu. Turn it on there, and you're findable as `@name@` from Mastodon and other fediverse apps. - Follows are accepted automatically, or wait for your approval if you turn that on diff --git a/frontend/css/style.css b/frontend/css/style.css index 94973b2..8df0ab6 100644 --- a/frontend/css/style.css +++ b/frontend/css/style.css @@ -206,23 +206,91 @@ code { } .account { + position: relative; /* anchors the menu */ margin-left: auto; - display: flex; - gap: 1rem; - align-items: center; color: var(--ink-soft); } -.account-link { +.account-trigger { display: flex; gap: 0.5rem; align-items: center; + padding: 0.25rem 0.5rem 0.25rem 0.25rem; + border: 1px solid transparent; + border-radius: var(--radius-control); + background: none; color: inherit; - text-decoration: none; + font: inherit; + cursor: pointer; } -.account-link:hover .account-name { +.account-trigger:hover, +.account-trigger[aria-expanded="true"] { color: var(--ink); + border-color: var(--rule); + background: var(--paper-raised); +} + +.account-trigger[data-current] .account-name { + color: var(--ink); +} + +/* A three-line "hamburger" icon, drawn with two borders and a shadow-free centre bar */ +.account-icon { + width: 1rem; + height: 0.7rem; + border-block: 2px solid currentColor; + background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat; +} + +.account-menu { + position: absolute; + top: calc(100% + 0.35rem); + right: 0; + z-index: 10; + min-width: 12rem; + margin: 0; + padding: 0.35rem; + list-style: none; + background: var(--paper-raised); + border: 1px solid var(--rule); + border-radius: var(--radius-control); + box-shadow: 0 8px 24px rgb(0 0 0 / 0.18); +} + +.account-menu[hidden] { + display: none; +} + +.account-menu-item { + display: block; + width: 100%; + padding: 0.5rem 0.75rem; + border: 0; + border-radius: calc(var(--radius-control) - 2px); + background: none; + color: var(--ink-soft); + font: inherit; + text-align: left; + text-decoration: none; + cursor: pointer; +} + +.account-menu-item:hover, +.account-menu-item:focus-visible { + color: var(--ink); + background: var(--bar); +} + +.account-menu-item[aria-current="page"] { + color: var(--ink); + font-weight: 600; +} + +.account-menu-end { + margin-top: 0.35rem; + padding-top: 0.35rem; + border-top: 1px solid var(--rule); } .account-avatar { @@ -864,9 +932,13 @@ input { margin-inline: -8px; } - .account { - margin-left: 0; - width: 100%; + /* Just the picture and the icon; the name is still the button's accessible label */ + .account-name { + display: none; + } + + .account-menu { + min-width: min(16rem, calc(100vw - 32px)); } .keys, diff --git a/frontend/js/account.js b/frontend/js/account.js index 69a780b..6ee6540 100644 --- a/frontend/js/account.js +++ b/frontend/js/account.js @@ -29,6 +29,8 @@ async function change(action, done) { say(h("p", { class: "notice notice-ok" }, done)); } catch (error) { say(errorBox(describeError(error))); + // The change may have half-happened, or the page was out of date: show what's true now. + user = await api("/auth/me").catch(() => user); } render(); const slot = document.querySelector(".account-avatar"); diff --git a/frontend/js/layout.js b/frontend/js/layout.js index f56ad1c..2196b96 100644 --- a/frontend/js/layout.js +++ b/frontend/js/layout.js @@ -8,6 +8,12 @@ const NAV = [ ["index.html", "Overview"], ["history.html", "History"], ["art.html", "Album art"], +]; + +// Account pages live in the menu under the user's name. "Sharing" joins them (after +// Profile) when the server federates. +const MENU = [ + ["account.html", "Profile"], ["apps.html", "Apps"], ["sessions.html", "Sessions"], ["import.html", "Import"], @@ -22,20 +28,9 @@ export async function signedInPage(active) { const header = document.getElementById("site-header"); replace(header, brand(), nav(active)); const user = await api("/auth/me"); - addSharingLink(header.querySelector("nav ul"), active); - header.append( - h( - "div", - { class: "account" }, - h( - "a", - { class: "account-link", href: "account.html", title: "Your profile image" }, - h("span", { class: "account-avatar" }, avatarImage(user, "avatar-sm")), - h("span", { class: "account-name" }, user.username), - ), - h("button", { type: "button", class: "link-button", onclick: signOut }, "Sign out"), - ), - ); + const menu = accountMenu(user, active); + header.append(menu.element); + addSharingLink(menu.list, active); return user; } @@ -67,6 +62,95 @@ function nav(active) { ); } +// The account menu: a button showing the user's picture and name that opens a list of +// account pages and "Sign out". Returns the element and its
    (for late additions). +function accountMenu(user, active) { + const list = h("ul", { class: "account-menu", id: "account-menu", hidden: true }); + for (const [href, label] of MENU) list.append(menuLink(href, label, active)); + list.append( + h( + "li", + { class: "account-menu-end" }, + h("button", { type: "button", class: "account-menu-item", onclick: signOut }, "Sign out"), + ), + ); + + const trigger = h( + "button", + { + type: "button", + class: "account-trigger", + "aria-haspopup": "true", + "aria-expanded": "false", + "aria-controls": "account-menu", + "aria-label": `Account menu for ${user.username}`, + }, + h("span", { class: "account-avatar" }, avatarImage(user, "avatar-sm")), + h("span", { class: "account-name" }, user.username), + h("span", { class: "account-icon", "aria-hidden": "true" }), + ); + const element = h("div", { class: "account" }, trigger, list); + + const items = () => [...list.querySelectorAll("a, button")]; + const setOpen = (open, focus) => { + list.hidden = !open; + trigger.setAttribute("aria-expanded", String(open)); + if (open && focus === "first") items()[0]?.focus(); + if (open && focus === "last") items().at(-1)?.focus(); + if (!open && focus) trigger.focus(); + }; + + trigger.addEventListener("click", () => setOpen(list.hidden)); + trigger.addEventListener("keydown", (event) => { + if (event.key === "ArrowDown") { + event.preventDefault(); + setOpen(true, "first"); + } else if (event.key === "ArrowUp") { + event.preventDefault(); + setOpen(true, "last"); + } + }); + list.addEventListener("keydown", (event) => { + const all = items(); + const at = all.indexOf(document.activeElement); + if (event.key === "Escape") { + setOpen(false, true); + } else if (event.key === "ArrowDown") { + event.preventDefault(); + all[(at + 1) % all.length].focus(); + } else if (event.key === "ArrowUp") { + event.preventDefault(); + all[(at - 1 + all.length) % all.length].focus(); + } else if (event.key === "Home") { + event.preventDefault(); + all[0].focus(); + } else if (event.key === "End") { + event.preventDefault(); + all.at(-1).focus(); + } + }); + // Close when focus or a click lands outside the menu. + document.addEventListener("click", (event) => { + if (!element.contains(event.target)) setOpen(false); + }); + element.addEventListener("focusout", (event) => { + if (event.relatedTarget && !element.contains(event.relatedTarget)) setOpen(false); + }); + document.addEventListener("keydown", (event) => { + if (event.key === "Escape" && !list.hidden) setOpen(false, true); + }); + + // Mark the trigger when the page being viewed is one of the menu's. + if (MENU.some(([href]) => href === active) || active === SHARING) { + trigger.setAttribute("data-current", "true"); + } + return { element, list }; +} + +function menuLink(href, label, active) { + return h("li", {}, h("a", { class: "account-menu-item", href, "aria-current": href === active ? "page" : false }, label)); +} + async function signOut() { try { await api("/auth/logout", { method: "POST" }); @@ -101,9 +185,10 @@ async function federationAvailable() { return available; } +const SHARING = "sharing.html"; + async function addSharingLink(list, active) { - if (!list || !(await federationAvailable())) return; - const href = "sharing.html"; - list.append(h("li", {}, h("a", { href, "aria-current": href === active ? "page" : false }, "Sharing"))); + if (!(await federationAvailable())) return; + list.children[0].after(menuLink(SHARING, "Sharing", active)); // right after Profile }