Files
muse/web/components/shell/sidebar.tsx
Aryan SinghandClaude Opus 5 e1b7b69261 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:33:52 -05:00

120 lines
4.4 KiB
TypeScript

"use client";
import * as React from "react";
import { motion } from "framer-motion";
import { Music2 } from "lucide-react";
import { cn } from "@/lib/utils";
import { href, type Nav, type Tab } from "@/lib/nav";
import { useMotionOK, spring } from "@/lib/motion";
import { NAV } from "./nav-items";
/**
* Sidebar navigation, the pattern Apple uses in Music, Mail, Finder and
* Settings. It replaces a horizontally scrolling row of pills, which is a
* mobile-web affordance that had been left on the desktop layout too.
*
* Collapses to a 68px icon rail between 768 and 1024, where a 240px sidebar
* would eat a third of the window.
*/
export function Sidebar({
nav,
go,
badges,
rail,
visible,
}: {
nav: Nav;
go: (n: Nav) => void;
badges: Partial<Record<Tab, number>>;
rail: boolean;
visible: (t: Tab) => boolean;
}) {
const ok = useMotionOK();
const groups = ["Library", "Activity", "Manage"] as const;
return (
<nav
aria-label="Sections"
className={cn(
"material sticky top-0 hidden h-dvh shrink-0 flex-col gap-1 border-r border-edge",
"md:flex",
rail ? "w-[var(--rail-w)] items-center px-2 py-3" : "w-[var(--sidebar-w)] px-3 py-3",
)}
>
<div className={cn("mb-4 flex items-center gap-2.5", rail ? "justify-center" : "px-2")}>
<span className="grid h-8 w-8 shrink-0 place-items-center rounded-card bg-accent text-[var(--accent-ink)]">
<Music2 className="h-4 w-4" />
</span>
{!rail && <span className="text-headline tracking-tight">muse</span>}
</div>
{groups.map((g) => {
const items = NAV.filter((n) => n.group === g && visible(n.tab));
if (!items.length) return null;
return (
<div key={g} className="mb-2 w-full">
{!rail && (
<h2 className="mb-1 px-2 text-caption font-semibold uppercase tracking-[0.06em] text-mute">
{g}
</h2>
)}
<ul className="flex flex-col gap-0.5">
{items.map(({ tab, label, icon: Icon }) => {
const on = nav.tab === tab;
const badge = badges[tab] ?? 0;
return (
<li key={tab}>
<a
href={href({ tab })}
aria-current={on ? "page" : undefined}
title={rail ? label : undefined}
onClick={(e) => {
// Left-click navigates in place; cmd/ctrl-click still
// opens a real new tab, because these are real links.
if (e.metaKey || e.ctrlKey || e.shiftKey) return;
e.preventDefault();
go({ tab });
}}
className={cn(
"focus-ring relative flex items-center rounded-control text-callout",
"font-medium transition-colors duration-150",
rail ? "h-9 w-9 justify-center" : "gap-2.5 px-2 py-1.5",
on ? "text-ink" : "text-dim hover:bg-[var(--faint)] hover:text-ink",
)}
>
{on && (
<motion.span
layoutId="nav-selection"
transition={ok ? spring : { duration: 0 }}
className="absolute inset-0 rounded-control bg-[var(--surface-3)]"
/>
)}
<Icon className="relative h-4 w-4 shrink-0" />
{!rail && <span className="relative flex-1 clamp1">{label}</span>}
{badge > 0 && (
<span
className={cn(
"shrink-0 rounded-pill text-caption font-bold nums",
rail
? "absolute -right-1 -top-1 h-4 min-w-4 px-1 text-center leading-4"
: "relative px-1.5",
tab === "review"
? "bg-warn/20 text-warn"
: "bg-accent-soft text-accent",
)}
>
{badge}
</span>
)}
</a>
</li>
);
})}
</ul>
</div>
);
})}
</nav>
);
}