Redesign the song page around the dashboard's front-panel look
CI / validate-monitoring (push) Successful in 11s
CI / lint (push) Successful in 17s
CI / federation-interop (push) Successful in 1m40s
CI / test (push) Successful in 3m16s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / trigger-deploy (push) Skipped
CI / notify (push) Successful in 6s
CI / validate-monitoring (pull_request) Successful in 9s
CI / lint (pull_request) Successful in 18s
CI / federation-interop (pull_request) Successful in 1m10s
CI / test (pull_request) Successful in 4m33s
CI / images (pull_request) Skipped
CI / assets (pull_request) Skipped
CI / python-package (pull_request) Skipped
CI / trigger-deploy (pull_request) Skipped
CI / notify (pull_request) Successful in 6s
CI / validate-monitoring (push) Successful in 11s
CI / lint (push) Successful in 17s
CI / federation-interop (push) Successful in 1m40s
CI / test (push) Successful in 3m16s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / trigger-deploy (push) Skipped
CI / notify (push) Successful in 6s
CI / validate-monitoring (pull_request) Successful in 9s
CI / lint (pull_request) Successful in 18s
CI / federation-interop (pull_request) Successful in 1m10s
CI / test (pull_request) Successful in 4m33s
CI / images (pull_request) Skipped
CI / assets (pull_request) Skipped
CI / python-package (pull_request) Skipped
CI / trigger-deploy (pull_request) Skipped
CI / notify (pull_request) Successful in 6s
Previously the song page was a plain heading, a bare metadata list and a history log. Now it gets its own moment on the glowing amber display, reusing the dashboard's .panel/.display/.readouts/ .spectrum components verbatim: the track name lit up like a now-playing display, play/first-played/last-played readouts, and a 90-day per-track play-activity chart. Extracted the segmented spectrum chart out of dashboard.js into a shared frontend/js/spectrum.js so both pages use the same renderer; the dashboard's own output is unchanged. Verified manually in-browser: the panel renders correctly, an artist name with a slash round-trips, the not-found and no-query-params states render into the panel, and the dashboard's spectrum chart is pixel-for-pixel unchanged after the extraction. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
86bf9fd302
commit
ae24c4a00e
4 files changed
+90
-67
No files matched your search
+31
-14
@@ -1,10 +1,10 @@
|
||||
import { api } from "./api.js";
|
||||
import { errorBox, formatDate, formatDay, formatDuration, formatTime, h, num, replace } from "./dom.js";
|
||||
import { signedInPage } from "./layout.js";
|
||||
import { spectrum } from "./spectrum.js";
|
||||
|
||||
const PER_PAGE = 50;
|
||||
const title = document.getElementById("song-title");
|
||||
const subtitle = document.getElementById("song-subtitle");
|
||||
const panel = document.getElementById("panel");
|
||||
const meta = document.getElementById("song-meta");
|
||||
const history = document.getElementById("song-history");
|
||||
const pager = document.getElementById("pager");
|
||||
@@ -17,7 +17,7 @@ const track = params.get("track") ?? "";
|
||||
const page = Math.max(1, Number.parseInt(params.get("page"), 10) || 1);
|
||||
|
||||
if (!artist || !track) {
|
||||
replace(history, h("p", { class: "notice" }, "Use the search box on the dashboard to find a song."));
|
||||
replace(panel, h("p", { class: "notice" }, "Use the search box on the dashboard to find a song."));
|
||||
} else {
|
||||
try {
|
||||
const result = await api(
|
||||
@@ -25,12 +25,10 @@ if (!artist || !track) {
|
||||
);
|
||||
render(result);
|
||||
} catch (error) {
|
||||
title.textContent = track;
|
||||
subtitle.textContent = `by ${artist}`;
|
||||
replace(
|
||||
history,
|
||||
panel,
|
||||
error.status === 404
|
||||
? h("p", { class: "notice" }, "You've never scrobbled this song.")
|
||||
? h("p", { class: "notice" }, `You've never scrobbled "${track}" by ${artist}.`)
|
||||
: errorBox(error.message),
|
||||
);
|
||||
}
|
||||
@@ -38,18 +36,26 @@ if (!artist || !track) {
|
||||
|
||||
function render(result) {
|
||||
document.title = `${result.track} · Scrobbler`;
|
||||
title.textContent = result.track;
|
||||
subtitle.textContent = `by ${result.artist}`;
|
||||
|
||||
const m = result.metadata;
|
||||
|
||||
const display = h(
|
||||
"div",
|
||||
{ class: "display" },
|
||||
h("p", { class: "display-status" }, "Now viewing"),
|
||||
h("p", { class: "display-track" }, result.track),
|
||||
h(
|
||||
"p",
|
||||
{ class: "display-meta" },
|
||||
h("strong", {}, result.artist),
|
||||
m.album ? [" from ", h("strong", {}, m.album)] : null,
|
||||
),
|
||||
);
|
||||
replace(panel, display, readouts(m), spectrum(result.counts, `Plays of ${result.track}`, "90 days"));
|
||||
|
||||
const row = (label, value) =>
|
||||
value === null || value === undefined ? null : h("div", {}, h("dt", {}, label), h("dd", {}, value));
|
||||
replace(
|
||||
meta,
|
||||
row("Plays", num(m.playcount)),
|
||||
row("First played", formatDate(m.first_played_at)),
|
||||
row("Last played", formatDate(m.last_played_at)),
|
||||
row("Album", m.album),
|
||||
row("Album artist", m.album_artist),
|
||||
row("Track number", m.track_number),
|
||||
row("Duration", m.duration ? formatDuration(m.duration) : null),
|
||||
@@ -95,3 +101,14 @@ function render(result) {
|
||||
: h("span"),
|
||||
);
|
||||
}
|
||||
|
||||
function readouts(m) {
|
||||
const item = (value, label) => h("div", {}, h("dt", {}, label), h("dd", {}, value));
|
||||
return h(
|
||||
"dl",
|
||||
{ class: "readouts" },
|
||||
item(num(m.playcount), "plays"),
|
||||
item(formatDate(m.first_played_at), "first played"),
|
||||
item(formatDate(m.last_played_at), "last played"),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user