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