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
This commit is contained in:
1 parent
0d49311848
commit
b509cd2b60
24 files changed
+1879
No files matched your search
@@ -0,0 +1,62 @@
|
||||
// Shared page shell: site header, navigation, sign-in guard.
|
||||
|
||||
import { api, getToken, redirectToLogin, setToken } from "./api.js";
|
||||
import { h, replace } from "./dom.js";
|
||||
|
||||
const NAV = [
|
||||
["index.html", "Overview"],
|
||||
["history.html", "History"],
|
||||
["apps.html", "Apps"],
|
||||
["sessions.html", "Sessions"],
|
||||
];
|
||||
|
||||
// Renders the header and returns the signed-in user (redirecting if there isn't one).
|
||||
export async function signedInPage(active) {
|
||||
if (!getToken()) {
|
||||
redirectToLogin();
|
||||
return new Promise(() => {}); // navigation is under way
|
||||
}
|
||||
const header = document.getElementById("site-header");
|
||||
replace(header, brand(), nav(active));
|
||||
const user = await api("/auth/me");
|
||||
header.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "account" },
|
||||
h("span", { class: "account-name" }, user.username),
|
||||
h("button", { type: "button", class: "link-button", onclick: signOut }, "Sign out"),
|
||||
),
|
||||
);
|
||||
return user;
|
||||
}
|
||||
|
||||
export function publicPage() {
|
||||
replace(document.getElementById("site-header"), brand());
|
||||
}
|
||||
|
||||
function brand() {
|
||||
return h("a", { class: "brand", href: "index.html" }, h("span", { class: "brand-mark", "aria-hidden": "true" }), "Scrobbler");
|
||||
}
|
||||
|
||||
function nav(active) {
|
||||
return h(
|
||||
"nav",
|
||||
{ "aria-label": "Main" },
|
||||
h(
|
||||
"ul",
|
||||
{},
|
||||
NAV.map(([href, label]) =>
|
||||
h("li", {}, h("a", { href, "aria-current": href === active ? "page" : false }, label)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async function signOut() {
|
||||
try {
|
||||
await api("/auth/logout", { method: "POST" });
|
||||
} finally {
|
||||
setToken(null);
|
||||
location.href = "login.html";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user