mirror of
https://github.com/narrrl/pl8list-rewind.git
synced 2026-11-19 01:25:03 +01:00
Redesign the bar, sheets and cards, and add likes queue, history and sleep timer
Feed modes move into tabs in the bar; likes, history, filters and settings, and account open as one kind of sheet: a drawer on wide screens, a bottom sheet with a drag handle on phones, with a scrim, Esc, a focus trap and focus restore. Cards get an artist avatar, follow and radio pills, a "new" chip, counts under round action buttons, an up-next pill and a redrawn waveform with rounded bars, a reflection and the buffered range. The start overlay names the track behind a big round play button. New: undo on dislike, a searchable likes list that plays as a queue (in order or shuffled), a local history of what played, deep links to a track (?t=handle/slug), a sleep timer, adjustable crossfade, bass boost, wheel up (w or a long press on the drop) and more keys.
This commit is contained in:
1 parent
53ac54b178
commit
62b28bd30e
10 files changed
+1312
-339
No files matched your search
+54
-13
@@ -20,6 +20,12 @@ export interface CardActions {
|
||||
// Uploads are often titled after their file name.
|
||||
export const cleanTitle = (t: string) => t.replace(/\.(wav|mp3|flac|aiff?|ogg|m4a)$/i, "");
|
||||
export const fmtTime = (s: number) => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, "0")}`;
|
||||
/// 1234 → "1.2k", as counts under the action buttons.
|
||||
export const compact = (n: number) =>
|
||||
n < 1000 ? String(n) : n < 10000 ? `${(n / 1000).toFixed(1).replace(/\.0$/, "")}k` : `${Math.round(n / 1000)}k`;
|
||||
const NEW_DAYS = 7; // uploads younger than this get a "new" chip
|
||||
const BAR = 3; // px per waveform bar, gap included
|
||||
const MIRROR = 0.28; // share of the waveform's height its reflection takes
|
||||
|
||||
const tpl = document.getElementById("card-tpl") as HTMLTemplateElement;
|
||||
|
||||
@@ -62,6 +68,7 @@ export class Card {
|
||||
if (img) {
|
||||
$(".bg").style.backgroundImage = `url("${img}")`;
|
||||
$(".art").style.backgroundImage = `url("${img}")`;
|
||||
$(".artist-avatar").style.backgroundImage = `url("${img}")`;
|
||||
if (this.accent) el.style.setProperty("--card-accent", this.accent);
|
||||
else accentFor(img).then((c) => {
|
||||
this.accent = c;
|
||||
@@ -72,6 +79,7 @@ export class Card {
|
||||
});
|
||||
} else {
|
||||
$(".initial").textContent = (t.artist_name || "?")[0].toUpperCase();
|
||||
$(".artist-avatar").textContent = (t.artist_name || "?")[0].toUpperCase();
|
||||
el.style.setProperty("--card-accent", accentForName(t.artist_name || "?"));
|
||||
}
|
||||
|
||||
@@ -91,6 +99,7 @@ export class Card {
|
||||
if (cls) s.className = cls;
|
||||
chips.append(s);
|
||||
};
|
||||
if (t.created_at && Date.now() - Date.parse(t.created_at) < NEW_DAYS * 86400e3) chip("new", "new");
|
||||
if (t.bpm) chip(`${Math.round(t.bpm)} bpm`);
|
||||
if (t.key) chip(t.key);
|
||||
chip(t.price ? `$${t.price}` : "free", t.price ? "" : "free");
|
||||
@@ -98,9 +107,11 @@ export class Card {
|
||||
// Tempo tags repeat the BPM chip.
|
||||
for (const tag of (t.tags ?? []).filter((g) => !/^\d+$/.test(g)).slice(0, 4)) chip(tag, "tag");
|
||||
|
||||
$(".counts").textContent =
|
||||
`${t.saves} saves · ${t.downloads} downloads · ${t.comments} comments` +
|
||||
(t.purchases ? ` · ${t.purchases} sold` : "");
|
||||
$(".counts").textContent = [t.downloads && `${compact(t.downloads)} downloads`, t.purchases && `${compact(t.purchases)} sold`]
|
||||
.filter(Boolean)
|
||||
.join(" · ");
|
||||
$(".saves").textContent = compact(t.saves);
|
||||
$(".comments").textContent = compact(t.comments);
|
||||
|
||||
$(".like").addEventListener("click", () => this.actions.like(this));
|
||||
$(".dislike").addEventListener("click", () => this.actions.dislike(this));
|
||||
@@ -143,8 +154,10 @@ export class Card {
|
||||
showFollow(): void {
|
||||
const btn = this.el?.querySelector(".follow");
|
||||
if (!btn) return;
|
||||
btn.classList.toggle("on", !!this.track.followed);
|
||||
btn.textContent = this.track.followed ? "following" : "follow";
|
||||
const on = !!this.track.followed;
|
||||
btn.classList.toggle("on", on);
|
||||
btn.querySelector("span")!.textContent = on ? "following" : "follow";
|
||||
btn.querySelector("use")!.setAttribute("href", on ? "#i-check" : "#i-plus");
|
||||
}
|
||||
|
||||
setTime(seconds: number): void {
|
||||
@@ -153,19 +166,24 @@ export class Card {
|
||||
}
|
||||
|
||||
private lastProgress = 0;
|
||||
private lastBuffered = 0;
|
||||
|
||||
/// Draw the waveform with `progress` (0..1) played. Cheap to call every frame:
|
||||
/// Draw the waveform with `progress` (0..1) played and up to `buffered` (0..1)
|
||||
/// loaded: rounded bars standing on a line, the played ones in the card's colour
|
||||
/// with a soft glow, and a faint reflection under them. Cheap to call every frame:
|
||||
/// it only redraws when a bar changes colour or the size changed.
|
||||
drawWave(progress: number, force = false): void {
|
||||
drawWave(progress: number, force = false, buffered = this.lastBuffered): void {
|
||||
if (this.dragging && !force) return;
|
||||
this.lastProgress = progress;
|
||||
this.lastBuffered = buffered;
|
||||
const canvas = this.canvas;
|
||||
if (!canvas) return;
|
||||
const w = canvas.clientWidth, h = canvas.clientHeight;
|
||||
if (!w) return;
|
||||
const bars = Math.max(1, Math.floor(w / 3));
|
||||
const bars = Math.max(1, Math.floor(w / BAR));
|
||||
const played = Math.round(progress * bars);
|
||||
const key = `${w}x${h}:${played}`;
|
||||
const loaded = Math.round(buffered * bars);
|
||||
const key = `${w}x${h}:${played}:${loaded}`;
|
||||
if (!force && key === this.drawn) return;
|
||||
this.drawn = key;
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
@@ -179,12 +197,35 @@ export class Card {
|
||||
const data = this.track.waveform || [];
|
||||
const max = Math.max(1, ...data);
|
||||
const accent = getComputedStyle(canvas).getPropertyValue("--card-accent").trim() || "#ff4d6d";
|
||||
const base = Math.round(h * (1 - MIRROR)) - 1;
|
||||
const below = h - base - 2;
|
||||
const level = (i: number) => (data.length ? data[Math.floor((i / bars) * data.length)] / max : 0.15);
|
||||
const grad = ctx.createLinearGradient(0, base, 0, 0);
|
||||
grad.addColorStop(0, accent);
|
||||
grad.addColorStop(0.65, accent);
|
||||
grad.addColorStop(1, "#fff");
|
||||
for (let i = 0; i < bars; i++) {
|
||||
const v = data.length ? data[Math.floor((i / bars) * data.length)] / max : 0.15;
|
||||
const bh = Math.max(2, v * h);
|
||||
ctx.fillStyle = i < played ? accent : "rgba(255,255,255,0.35)";
|
||||
ctx.fillRect(i * 3, (h - bh) / 2, 2, bh);
|
||||
const v = level(i);
|
||||
const x = i * BAR;
|
||||
const top = Math.max(2, v * (base - 2));
|
||||
const color = i < played ? accent : i < loaded ? "rgba(255,255,255,0.5)" : "rgba(255,255,255,0.22)";
|
||||
// The bar, standing on the line; played ones glow.
|
||||
ctx.globalAlpha = 1;
|
||||
ctx.fillStyle = i < played ? grad : color;
|
||||
ctx.shadowBlur = i < played ? 6 : 0;
|
||||
ctx.shadowColor = accent;
|
||||
ctx.beginPath();
|
||||
ctx.roundRect(x, base - top, BAR - 1, top, 1);
|
||||
ctx.fill();
|
||||
// Its reflection, faint, under the line.
|
||||
ctx.shadowBlur = 0;
|
||||
ctx.globalAlpha = 0.22;
|
||||
ctx.fillStyle = color;
|
||||
ctx.beginPath();
|
||||
ctx.roundRect(x, base + 2, BAR - 1, Math.max(1, v * below), 1);
|
||||
ctx.fill();
|
||||
}
|
||||
ctx.globalAlpha = 1;
|
||||
}
|
||||
|
||||
/// Loudness at `progress` from the waveform, 0..1. Stands in for the analyser
|
||||
|
||||
Reference in new issue
Block a user