Files
muse/web/components/track-row.tsx
T
Aryan SinghandClaude Opus 5 171e117f7c Recover blocked searches, fall through to the next peer, rebuild the UI
Measured against a live instance: 47 failed jobs against 33 imported. Three
independent causes, all of which ended the request.

The Soulseek server filters some artist names. "Michael Jackson Billie Jean"
and bare "Michael Jackson" both return zero responses; "Billie Jean" returns
1083 files. The Weeknd, Kanye West and Frank Ocean behave the same way. Since
pick_and_enqueue sent exactly one query of `artist title`, every request for a
filtered artist failed reporting "searched 0 files" -- 28 of 29 occurrences.
search_queries() now walks a ladder, loosest last, ending at the bare title,
and escalates only when a search underdelivers so the common case still costs
one search. Dropping the artist from the query does not mean ignoring it:
match_ratio() looks for it in the folder path, where an organised share puts it.

A rejected transfer ended the request. pick_and_enqueue kept a running maximum
and discarded every runner-up, so "Transfer rejected: File not shared." -- a
per-file condition where candidate two almost always works -- was terminal, as
were timeouts and slskd's 500 on an unreachable peer. The ranked list is now
persisted on the job row, ordered to put a different peer next, and
try_next_candidate() advances through it. A job fails only once the list is
exhausted, and then reports every peer it tried and what each one said.

norm() destroyed every non-ASCII character, so "Beyonce" never matched
Beyonce, nor Bjork Bjork, nor Dont Don't. It now folds accents and drops
apostrophes while leaving & as a separator.

Also: availability outranks format in score(), because a FLAC behind 5000
queued users used to beat an immediately available MP3; transfers that stall or
that slskd forgets are abandoned instead of sitting in `downloading` forever;
searches are deleted only once finished, since deleting one mid-flight makes
slskd throw an optimistic-concurrency error and lose the record; a failed
search POST is retried rather than failing the job on one blip.

The UI moves to a sidebar shell -- rail at tablet, bottom bar on phones -- with
neutral chrome and the sampled artwork colour confined to hero areas rather
than repainting the whole interface. Adds URL routing, a primitive set under
components/ui, and a request sheet showing the attempt ladder. Fixes
hover:bg-glass-hi, which was never a valid class, so track rows and the search
field had no hover or focus state at all; a reduced-motion path that could
strand elements at opacity 0; the login page's hardcoded palette; and the
missing 404 and error boundaries.

tests/test_acquisition.py covers this path against a faked slskd. It had none.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 11:29:59 -05:00

171 lines
5.1 KiB
TypeScript

"use client";
import * as React from "react";
import { motion } from "framer-motion";
import { Play, Pause } from "lucide-react";
import { api, mmss, type Track } from "@/lib/api";
import { usePlayer } from "@/components/player";
import { useToast } from "@/components/toast";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
export function TrackRow({
track,
index,
showNumber,
showArtist = true,
showAlbum = true,
onAlbum,
onArtist,
onQueued,
}: {
track: Track;
index: number;
showNumber?: boolean;
showArtist?: boolean;
showAlbum?: boolean;
onAlbum?: (id: number) => void;
onArtist?: (id: number) => void;
onQueued?: () => void;
}) {
const { playing, toggle } = usePlayer();
const toast = useToast();
const [state, setState] = React.useState<"idle" | "busy" | "done">("idle");
const isPlaying = playing === track.deezer_id;
const queue = async () => {
setState("busy");
try {
await api.request(track);
setState("done");
toast(`Queued ${track.artist} — ${track.title}`);
onQueued?.();
} catch (e) {
setState("idle");
toast(`Could not queue: ${(e as Error).message}`, true);
}
};
const facts: React.ReactNode[] = [];
if (showAlbum && track.album)
facts.push(
track.album_id && onAlbum ? (
<button
key="al"
onClick={() => onAlbum(track.album_id!)}
className="hover:text-accent hover:underline cursor-pointer"
>
{track.album}
</button>
) : (
<span key="al">{track.album}</span>
),
);
if (track.year) facts.push(<span key="yr">{track.year}</span>);
if (track.genre) facts.push(<span key="gn">{track.genre}</span>);
return (
<motion.div
layout
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: Math.min(index * 0.022, 0.4), type: "spring", stiffness: 380, damping: 34 }}
whileHover={{ y: -1 }}
className={cn(
"card rounded-card flex items-center gap-3 py-2.5 pl-2.5 pr-3",
"transition-colors hover:bg-[var(--surface-2)] hover:border-edge-hi",
isPlaying && "border-accent-line bg-accent-soft",
)}
>
{showNumber && (
<div className="w-6 shrink-0 text-right text-callout text-dim tabular-nums">
{track.track ?? ""}
</div>
)}
<button
onClick={() => toggle(track)}
disabled={!track.preview}
aria-label={track.preview ? `Preview ${track.title}` : "No preview available"}
className={cn(
"relative w-[50px] h-[50px] shrink-0 rounded-[9px] overflow-hidden bg-faint group",
track.preview ? "cursor-pointer" : "cursor-default",
)}
>
{track.cover && (
/* eslint-disable-next-line @next/next/no-img-element */
<img
src={track.cover}
alt=""
loading="lazy"
className="w-full h-full object-cover"
onError={(e) => (e.currentTarget.style.visibility = "hidden")}
/>
)}
{track.preview && (
<div
className={cn(
"absolute inset-0 grid place-items-center bg-black/50 text-white",
"transition-opacity duration-200",
isPlaying ? "opacity-100" : "opacity-0 group-hover:opacity-100",
)}
>
{isPlaying ? (
<Pause className="w-[18px] h-[18px] fill-current" />
) : (
<Play className="w-[18px] h-[18px] fill-current" />
)}
</div>
)}
</button>
<div className="flex-1 min-w-0">
<div className="text-body font-semibold tracking-[-0.15px] clamp1">
{track.title}
{track.explicit && (
<span className="ml-1.5 align-[1px] inline-block rounded-[3px] border border-edge bg-faint px-1 text-[9px] font-bold text-dim">
E
</span>
)}
</div>
<div className="mt-px text-callout text-dim clamp1">
{showArtist && track.artist_id && onArtist ? (
<button
onClick={() => onArtist(track.artist_id!)}
className="hover:text-accent hover:underline cursor-pointer"
>
{track.artist}
</button>
) : showArtist ? (
<span>{track.artist}</span>
) : null}
{facts.map((f, i) => (
<React.Fragment key={i}>
{(showArtist || i > 0) && <span className="mx-1.5 opacity-50">·</span>}
{f}
</React.Fragment>
))}
</div>
</div>
<div className="hidden sm:block shrink-0 text-callout text-dim tabular-nums">
{track.length ? mmss(track.length) : ""}
</div>
<Button
variant="outline"
size="pill"
onClick={queue}
disabled={state !== "idle"}
className={cn(
"shrink-0",
state === "done" && "border-ok/50 text-ok bg-ok/10 hover:bg-ok/10 hover:text-ok hover:border-ok/50",
)}
>
{state === "idle" ? "Get" : state === "busy" ? "…" : "Queued"}
</Button>
</motion.div>
);
}