import { Icon } from '../lib/icons'
/** A background job's progress, shown at the right of the bar. */
export interface StatusJob {
label: string
done: number
/** 0 until the job knows its size → indeterminate bar. */
total: number
/** What it is working on right now, e.g. the current track's title. This is
* the one part that shortens when space runs out. */
detail?: string
/** How far the current item has got, 0..1: the TOP half of a split bar (the
* bottom half is the whole job, which moves within an item too). */
fraction?: number
/** What the current item is doing ("separating 41 %") — never truncated. */
status?: string
cancelling?: boolean
onCancel: () => void
/** `bytes`: done/total are byte counts (a download), shown in MB. */
unit?: 'bytes'
}
interface Props {
showing: number
total: number
sourceName: string
/** Rows currently selected; shown only when non-zero. */
selected?: number
job?: StatusJob | null
loading?: boolean
collectionName?: string | null
onChangeCollection?: () => void
}
export function StatusBar({
showing,
total,
sourceName,
selected = 0,
job,
loading,
collectionName,
onChangeCollection,
}: Props) {
return (
{/* The view's name gives way on a narrow window — the job section on the
right is a fixed width and does not. */}
{sourceName}
·
{loading ? (
Loading…
) : (
{showing === total ? (
<>{total.toLocaleString()} tracks>
) : (
<>
{showing.toLocaleString()} of {total.toLocaleString()} tracks
>
)}
)}
{selected > 0 && (
<>
·{selected.toLocaleString()} selected
>
)}
{job && (
// FIXED positions: the section is a fixed width, and everything before
// the name has a fixed width too (the count sized for its largest value,
// the status a fixed slot), so neither a long track name nor
// "decoding" → "separating" can move the bar. The name fills what is
// left and is the only thing that shortens.
{job.label}
{job.total > 1 && job.unit !== 'bytes' && (
{Math.min(job.done + 1, job.total)}/{job.total}
)}
{/* One bar, split horizontally when the job reports per-item progress
(a stem conversion): TOP = the current item, 0-100 % across the
full width; BOTTOM = the whole job, (done + fraction) / total, so
it moves within a long item too. Other jobs: one full-height bar. */}
{(() => {
const fill =
'absolute inset-y-0 left-0 rounded-full bg-gradient-to-r from-[var(--amb-1)] to-accent shadow-[0_0_6px_var(--color-accent)] transition-[width] duration-300'
const pct = (v: number) => `${Math.max(0, Math.min(1, v)) * 100}%`
if (job.total <= 0) {
return (
)
}
const overall = (job.done + (job.unit === 'bytes' ? 0 : job.fraction ?? 0)) / job.total
if (job.unit === 'bytes' || !job.status) {
return (
)
}
return (
)
})()}
{/* Status at its natural width: it sits AFTER the bar, so it cannot
move it — and a fixed slot left a gap before the name. */}
{(job.cancelling || job.status || (job.unit === 'bytes' && job.total > 0)) && (
<>
{job.cancelling
? 'cancelling…'
: job.unit === 'bytes'
? `${Math.round(job.done / 1e6)} / ${Math.round(job.total / 1e6)} MB`
: job.status}
{job.detail && ·}
>
)}
{job.detail}