import { createEffect, createMemo, createSignal, For, Show, onSettled, untrack, type VoidComponent, } from "solid-js"; import { library } from "../lib/harvest"; import type { LibrarySong } from "../lib/harvest/types"; import { connection } from "../lib/connection"; import { favorites } from "../lib/favorites"; import { commandLine, type CommandLineHost } from "../lib/cli"; import { locate } from "../lib/locate"; import { useLibraryQuery } from "../lib/library/query"; import { count } from "../lib/print"; import { shareSong } from "../lib/share"; import { SubsonicClient } from "../lib/subsonic/client"; import { player } from "../lib/player"; import { randomIndex, randomStart } from "../lib/player/random"; import { albumRuns } from "../lib/library/rows"; import { albumCells, revealRowIndex, type GridAlbum } from "../lib/library/grid"; import { buildRows, durationParts, trackBadges, type LibraryRow } from "../lib/library/rows"; import { buildIndex, filterSongs } from "../lib/library/search"; import { traceRecompute } from "../lib/library/gridtrace"; import { AlbumGrid } from "./AlbumGrid"; import { HarvestLine, HarvestStatus } from "./HarvestProgress"; import { VirtualList } from "./VirtualList"; /** * What the cache says about one track, worn by the row that lists it: the row's own * background, painted the accent from the left as its bytes arrive — a determinate bar * at row scale, one pixel column of it per column of the body, and the full wash when * the track is cached (decoded or warmed). No indeterminate crawl anywhere: a bar that * pulses says "trust me" where this one can say how many of the bytes are actually * here, which is the difference the whole fetch-progress plumbing exists to afford. * * A component, and not reads inside `trackClass`: the row window is the hottest scope * in the app (see the note on the class builders), and a chunk-rate signal read there * would wake row construction once per chunk. In here, a chunk wakes one width. * * No branch on the state, even though there are two of them: cached is just the bar at * full width. Besides being the honest visual — a cached track is a finished download — * it keeps the element out of Show's children callback, whose body runs untracked, so * anything that branched on the state there would read the signals exactly once. */ const TrackCacheMark: VoidComponent<{ id: string }> = (props) => { const state = () => player().trackCacheState(props.id); const progress = () => player().trackFetchProgress(props.id); const pct = () => { if (state() === "cached") return 100; const p = progress(); if (!p || p.total <= 0) return 0; return Math.min(100, Math.round((p.received / p.total) * 100)); }; let fill: HTMLDivElement | undefined; // The width by effect rather than a tracked style attribute — the same reason the // query box sets its value by effect: one write per arriving chunk, reads in the // compute half and DOM in the effect half, as the other effects in this file. createEffect( () => pct(), (pctNow) => { if (fill) fill.style.width = `${pctNow}%`; }, { name: "cache-fill-width" }, ); return (