Files
Scrobbler/frontend/js/sessions.js
mattandClaude Opus 5.5 b509cd2b60
CI / lint (push) Successful in 9s
CI / test (push) Successful in 31s
CI / notify (push) Successful in 5s
Web UI: static HTML/CSS/JS frontend, hosted separately from the API
- Plain HTML + vanilla JS modules, no build step; talks to /api/v1 with
  a bearer token and only ever inserts server data as text
- Overview: now-playing dot-matrix display with live progress, totals,
  30-day plays meter, top artists/tracks by period, recent plays
- History (paged, grouped by day), Apps (create/delete, reveal/copy
  keys, player setup details), Sessions (revoke), sign-in approval page
  for the Last.fm desktop auth flow, sign in and registration
- Light and dark themes, responsive to phone widths, vendored fonts
  (SIL OFL) so the UI has no third-party requests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
2026-09-25 14:11:37 +01:00

61 lines
1.8 KiB
JavaScript

import { api } from "./api.js";
import { errorBox, formatDate, h, replace, timeAgo } from "./dom.js";
import { signedInPage } from "./layout.js";
const list = document.getElementById("sessions");
const messages = document.getElementById("messages");
await signedInPage("sessions.html");
await refresh();
async function refresh() {
try {
const sessions = await api("/sessions");
if (!sessions.length) {
replace(list, h("li", { class: "empty" }, "No players are signed in. They appear here once they sign in with an app's key."));
return;
}
replace(list, sessions.map(sessionRow));
} catch (error) {
replace(list, h("li", {}, errorBox(error.message)));
}
}
function sessionRow(session) {
const actions = h("div", { class: "confirm" });
const reset = () =>
replace(actions, h("button", { type: "button", class: "button button-quiet", onclick: ask }, "Revoke"));
const ask = () =>
replace(
actions,
h("button", { type: "button", class: "button button-danger", onclick: () => revoke(session, actions) }, "Revoke access"),
h("button", { type: "button", class: "button button-quiet", onclick: reset }, "Cancel"),
);
reset();
return h(
"li",
{},
h(
"div",
{ class: "row-head" },
h(
"span",
{},
h("span", { class: "row-title" }, session.app_name),
h("span", { class: "muted", title: formatDate(session.created_at) }, ` Signed in ${timeAgo(session.created_at)}`),
),
actions,
),
);
}
async function revoke(session, actions) {
try {
await api(`/sessions/${session.id}`, { method: "DELETE" });
await refresh();
replace(messages, h("p", { class: "notice notice-ok", role: "status" }, `Revoked ${session.app_name}.`));
} catch (error) {
replace(actions, errorBox(error.message));
}
}