Added device file exploration and file importing

This commit is contained in:
patben8 committed 2026-09-25 23:30:24 +02:00
1 parent b9d43dd7ea
commit bd425f8cd6
18 files changed
+1819 -120

No files matched your search

+350
View File
@@ -0,0 +1,350 @@
import { createPortal } from 'react-dom'
import { useEffect, useRef, useState, type ReactNode } from 'react'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type FolderAddPreview, type FolderAddRequest, type JobStatus } from '../api'
import { FolderPicker } from './FolderPicker'
/**
* Add browsed files to the collection — and, optionally, to a playlist or export.
*
* Copy vs. leave-in-place is ASKED every time, with nothing preselected: the
* right answer depends on the drive (a stick is about to be unplugged) and on
* how the DJ keeps their music, and a remembered default would quietly apply
* last week's answer to a different drive.
*
* A playlist or export target still needs the files in the collection first —
* both hold collection track ids — so the dialog says so rather than doing it
* silently. Files the collection already holds are not added again, but still
* go into the target.
*/
const POLL_MS = 300
function gb(bytes: number): string {
if (bytes >= 1e9) return `${(bytes / 1e9).toFixed(1)} GB`
if (bytes >= 1e6) return `${(bytes / 1e6).toFixed(0)} MB`
return `${(bytes / 1e3).toFixed(0)} kB`
}
export interface AddTarget {
kind: 'playlist' | 'export'
id: string
name: string
}
interface Props {
trackIds: string[]
target: AddTarget | null
onClose: () => void
onDone: (msg: string) => void
onError: (msg: string) => void
}
export function AddFilesDialog({ trackIds, target, onClose, onDone, onError }: Props) {
const qc = useQueryClient()
const [mode, setMode] = useState<'copy' | 'reference' | null>(null)
const [folder, setFolder] = useState('')
const [browsing, setBrowsing] = useState(false)
const [job, setJob] = useState<JobStatus | null>(null)
const [starting, setStarting] = useState(false)
const pollRef = useRef<number | null>(null)
// The same import folder as a device import: one place your copied music goes.
const prefs = useQuery({ queryKey: ['prefs'], queryFn: api.getPrefs })
const prefsLoaded = prefs.isSuccess
useEffect(() => {
if (!prefsLoaded || folder) return
const p = prefs.data as { importFolder?: string }
setFolder(p?.importFolder || '~/Music/Konduktor Imports')
}, [prefsLoaded, prefs.data, folder])
const body: FolderAddRequest = {
track_ids: trackIds,
// The preview needs A mode to size anything; "reference" costs nothing to
// ask about and is replaced as soon as the user picks.
mode: mode ?? 'reference',
destination: mode === 'copy' ? folder : null,
playlist_id: target?.kind === 'playlist' ? target.id : null,
export_id: target?.kind === 'export' ? target.id : null,
}
const preview = useQuery<FolderAddPreview>({
queryKey: ['folder-add-preview', trackIds, mode, folder, target?.id],
queryFn: () => api.folderAddPreview(body),
enabled: !job && (mode !== 'copy' || !!folder),
staleTime: 0,
gcTime: 0,
})
useEffect(() => {
if (!job || job.state !== 'running') return
pollRef.current = window.setInterval(async () => {
try {
const next = await api.job(job.id)
setJob(next)
if (next.state === 'running') return
if (pollRef.current) window.clearInterval(pollRef.current)
if (next.state === 'done') {
const r = next.result as { tracks?: number; track_ids?: string[] } | null
qc.invalidateQueries({ queryKey: ['tracks'] })
qc.invalidateQueries({ queryKey: ['playlists'] })
qc.invalidateQueries({ queryKey: ['playlist'] })
qc.invalidateQueries({ queryKey: ['collection'] })
qc.invalidateQueries({ queryKey: ['state'] })
qc.invalidateQueries({ queryKey: ['facets'] })
qc.invalidateQueries({ queryKey: ['folder-tracks'] })
if (target?.kind === 'export') {
qc.invalidateQueries({ queryKey: ['exports'] })
qc.invalidateQueries({ queryKey: ['export-contents', target.id] })
qc.invalidateQueries({ queryKey: ['export-tracks', target.id] })
qc.invalidateQueries({ queryKey: ['export-loose', target.id] })
}
const added = r?.tracks ?? 0
const total = r?.track_ids?.length ?? added
onDone(
target
? `Added ${total} track${total === 1 ? '' : 's'} to ${target.name}` +
(added ? ` (${added} new to your collection)` : '')
: `Added ${added} track${added === 1 ? '' : 's'} to your collection`,
)
} else if (next.state === 'failed') {
onError(next.error || 'Adding failed')
}
} catch (e) {
onError((e as Error).message)
if (pollRef.current) window.clearInterval(pollRef.current)
}
}, POLL_MS)
return () => {
if (pollRef.current) window.clearInterval(pollRef.current)
}
}, [job, qc, onDone, onError, target])
const start = async () => {
setStarting(true)
try {
setJob(await api.folderAdd(body))
} catch (e) {
onError((e as Error).message)
} finally {
setStarting(false)
}
}
const cancel = async () => {
if (!job) return
try {
await api.cancelJob(job.id)
} catch (e) {
onError((e as Error).message)
}
}
const p = preview.data
const running = job?.state === 'running'
const finished = job != null && job.state !== 'running'
const pct = job && job.total > 0 ? Math.min(100, (job.done / job.total) * 100) : null
const n = trackIds.length
const newCount = p?.importable ?? 0
const canAdd =
!starting && mode !== null && !!p && (newCount > 0 || (!!target && p.existing.length > 0)) &&
p.enough_space !== false
const title = target
? `Add ${n} track${n === 1 ? '' : 's'} to ${target.name}`
: `Add ${n} track${n === 1 ? '' : 's'} to your collection`
const option = (value: 'copy' | 'reference', label: string, detail: ReactNode) => (
<label
className={`flex cursor-pointer gap-3 rounded-lg px-3 py-2 ${
mode === value ? 'is-selected' : 'hover:bg-ink-850'
}`}
>
<input
type="radio"
name="add-mode"
checked={mode === value}
onChange={() => setMode(value)}
className="mt-0.5 accent-accent"
/>
<span className="min-w-0 flex-1">
<span className="block text-text">{label}</span>
<span className="block text-xs text-faint">{detail}</span>
</span>
</label>
)
return createPortal(
<>
{browsing && (
<FolderPicker
value={folder}
onChange={(path) => {
setFolder(path)
api.patchPrefs({ importFolder: path }).catch(() => {})
}}
onClose={() => setBrowsing(false)}
/>
)}
<div
aria-modal="true"
className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-[3px]"
>
<div className="w-full max-w-lg glass-overlay">
<div className="border-b border-line px-5 py-3">
<h2 className="text-sm font-semibold text-text">{title}</h2>
</div>
<div className="space-y-4 px-5 py-4 text-sm">
{!job && (
<>
{target && (
<div className="text-xs text-muted">
{target.kind === 'playlist' ? 'Playlists' : 'Exports'} hold tracks from your
collection, so these are added to the collection first.
</div>
)}
<div className="space-y-1">
{option(
'copy',
'Copy into your import folder',
<span className="flex items-center gap-2">
<span className="min-w-0 truncate font-mono" dir="rtl" title={folder}>
{/* LRM marks: in an rtl box (for left-truncation) a
leading "~" would otherwise be moved to the end. */}
{folder ? `\u200E${folder}\u200E` : 'Loading…'}
</span>
<button
onClick={(e) => {
e.preventDefault()
setBrowsing(true)
}}
className="shrink-0 text-accent hover:underline"
>
Change…
</button>
</span>,
)}
{option(
'reference',
'Leave them where they are',
'Your collection points at these files. Nothing is copied.',
)}
</div>
{mode === 'reference' && p?.removable && (
<div className="rounded well px-3 py-2 text-xs text-gold">
These files are on an external drive. They will go missing from your
collection whenever the drive is unplugged.
</div>
)}
{preview.isError && (
<div className="text-pink">{(preview.error as Error).message}</div>
)}
{mode && p && (
<div className="space-y-2">
<div className="text-text">
{newCount} new to your collection
{mode === 'copy' && (
<span className="text-muted"> · {gb(p.total_bytes)} to copy</span>
)}
</div>
{mode === 'copy' && p.free_bytes != null && (
<div className={p.enough_space === false ? 'text-pink' : 'text-faint'}>
{gb(p.free_bytes)} free
{p.enough_space === false && ' — not enough space'}
</div>
)}
{p.existing.length > 0 && (
<div className="rounded well px-3 py-2 text-xs text-muted">
{p.existing.length} {p.existing.length === 1 ? 'is' : 'are'} already in
your collection and will not be added again
{target ? ` — but will still go into ${target.name}` : ''}.
</div>
)}
{p.missing.length > 0 && (
<div className="rounded well px-3 py-2 text-xs text-pink">
{p.missing.length} file{p.missing.length === 1 ? ' is' : 's are'} no longer
there and will be skipped.
</div>
)}
{mode === 'copy' && p.duplicates.length > 0 && (
<div className="rounded well px-3 py-2 text-xs text-gold">
{p.duplicates.length} of these look like tracks your collection already
has. The copies will be added as new entries.
</div>
)}
</div>
)}
</>
)}
{job && (
<div className="space-y-3">
<div className="text-text">{job.message || 'Working…'}</div>
<div className="h-2 overflow-hidden rounded-full bg-well">
<div
className={`h-full transition-[width] duration-200 ${
job.state === 'failed' ? 'bg-pink' : 'bg-accent'
} ${pct == null ? 'w-1/3 animate-pulse' : ''}`}
style={pct == null ? undefined : { width: `${pct}%` }}
/>
</div>
{job.state === 'cancelled' && (
<div className="text-xs text-muted">
Cancelled. Nothing was added, and any copied files were removed.
</div>
)}
{job.state === 'failed' && <div className="text-xs text-pink">{job.error}</div>}
{job.state === 'done' && <div className="text-xs text-mint">Done.</div>}
</div>
)}
</div>
<div className="flex justify-end gap-2 border-t border-line px-5 py-3">
{running ? (
<>
<button
onClick={cancel}
className="btn-glass rounded-full px-3 py-1.5 text-sm text-muted hover:text-text"
>
Cancel
</button>
<button
onClick={onClose}
className="rounded-md px-3 py-1.5 text-sm text-faint hover:text-text"
title="It keeps running"
>
Hide
</button>
</>
) : (
<>
<button
onClick={onClose}
className="btn-glass rounded-full px-3 py-1.5 text-sm text-muted hover:text-text"
>
{finished ? 'Close' : 'Cancel'}
</button>
{!finished && (
<button
disabled={!canAdd}
onClick={start}
title={mode === null ? 'Choose whether to copy the files first' : undefined}
className="rounded-full btn-primary px-3 py-1.5 text-sm font-semibold disabled:opacity-40"
>
{starting ? 'Starting…' : 'Add'}
</button>
)}
</>
)}
</div>
</div>
</div>
</>,
document.body,
)
}
+266 -59
View File
@@ -1,20 +1,22 @@
import { useEffect } from 'react'
import { useEffect, useState, type ReactNode } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type PlaylistNode } from '../api'
import { api, type Drive, type PlaylistNode } from '../api'
import type { Source } from './Sidebar'
import { Icon } from '../lib/icons'
/**
* Plugged-in libraries, in the sidebar, the way rekordbox and Traktor show them.
* Every drive, in the sidebar: plugged-in ones under Devices, and the computer's
* own under an expandable Local Storage.
*
* The list genuinely changes while the app is open — a device is whatever stick
* is mounted — so unlike everything else in the sidebar this POLLS. It is a
* directory stat per mount point, which is cheap enough to do every few seconds
* and the only way a drive can appear without the user reloading.
* A drive carrying a OneLibrary library opens as a device, the way rekordbox and
* Traktor show a stick: its playlists appear under it and the ordinary track
* table browses it. EVERY drive — library or not — also has a Files tree, and
* selecting a folder there shows the audio directly in it (not its subfolders:
* the tree is how you get to those, and a click on a drive root must never walk
* the whole drive).
*
* Browsing a device reuses the ordinary track table and deck: the adapter
* projects a drive into the same generic model the collection uses, so there is
* nothing here that needs its own table, its own row or its own player.
* The list genuinely changes while the app is open, so unlike everything else in
* the sidebar this POLLS. Folder levels are fetched only when expanded.
*/
const POLL_MS = 4000
@@ -28,10 +30,21 @@ interface Props {
export function DevicesSection({ source, onSelect, onError, onImport }: Props) {
const qc = useQueryClient()
// Which rows are expanded, by a key per row kind. Not persisted: a tree
// reopening deep inside a drive that is no longer plugged in helps nobody.
const [expanded, setExpanded] = useState<Set<string>>(new Set())
const isOpenRow = (key: string) => expanded.has(key)
const setRow = (key: string, open: boolean) =>
setExpanded((prev) => {
const next = new Set(prev)
if (open) next.add(key)
else next.delete(key)
return next
})
const devices = useQuery({
queryKey: ['sources'],
queryFn: api.sources,
const drives = useQuery({
queryKey: ['drives'],
queryFn: api.drives,
refetchInterval: POLL_MS,
})
const open = useQuery({ queryKey: ['source'], queryFn: api.source })
@@ -64,24 +77,97 @@ export function DevicesSection({ source, onSelect, onError, onImport }: Props) {
onError: (e: Error) => onError(e.message),
})
const list = drives.data ?? []
const external = list.filter((d) => d.kind === 'external')
const local = list.filter((d) => d.kind === 'local')
// A drive can be physically unplugged while it is open. Nothing crashes — the
// routes just start failing — but leaving it selected would show a library
// that is not there, so fall back to the collection.
const stillPresent =
!openPath || (devices.data ?? []).some((d) => d.path === openPath)
// that is not there, so fall back to the collection. The same goes for a
// folder on it being browsed.
const stillPresent = !openPath || list.some((d) => d.library?.path === openPath)
useEffect(() => {
if (!openPath || stillPresent || eject.isPending) return
if (!drives.isSuccess || !openPath || stillPresent || eject.isPending) return
eject.mutate()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [openPath, stillPresent])
const list = devices.data ?? []
if (list.length === 0 && !openPath) return null
}, [openPath, stillPresent, drives.isSuccess])
const folderGone =
source.kind === 'folder' &&
drives.isSuccess &&
!list.some((d) => d.path === '/' || isInside(source.path, d.path))
useEffect(() => {
if (folderGone) onSelect({ kind: 'all' })
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [folderGone])
const viewingDevice = source.kind === 'device' || source.kind === 'device-playlist'
const driveRow = (d: Drive, depth: number) => {
const key = `drive:${d.path}`
const expandedHere = isOpenRow(key)
const isOpen = !!d.library && d.library.path === openPath
const onClick = () => {
if (d.library) {
setRow(key, true)
if (isOpen) onSelect({ kind: 'device' })
else openDevice.mutate(d.library.path)
} else {
setRow(key, !expandedHere)
}
}
return (
<div key={d.path}>
<TreeRow
depth={depth}
icon={<span className="text-gold"><Icon name="drive" size={15} /></span>}
label={d.name}
title={d.path}
expanded={expandedHere}
onToggle={() => setRow(key, !expandedHere)}
onClick={onClick}
selected={isOpen && source.kind === 'device'}
trailing={
isOpen && open.data?.tracks != null ? (
<span className="text-[10px] text-faint">{open.data.tracks}</span>
) : undefined
}
/>
{expandedHere && (
<>
{isOpen &&
(playlists.data ?? []).map((n) => (
<DevicePlaylistRow
key={n.id}
node={n}
depth={depth + 1}
source={source}
onSelect={onSelect}
/>
))}
<FolderRow
path={d.path}
name="Files"
viewName={d.name}
icon="folder"
depth={depth + 1}
source={source}
onSelect={onSelect}
isOpenRow={isOpenRow}
setRow={setRow}
/>
</>
)}
</div>
)
}
const localKey = 'local-storage'
const localOpen = isOpenRow(localKey)
// Shrinkable and self-scrolling, capped at 40%: a deep Files tree must give
// way before the playlists do, never push them off the sidebar.
return (
<>
<div className="flex max-h-[40%] min-h-28 flex-col">
<div className="mt-3 flex items-center justify-between px-4">
<span className="text-[10px] font-semibold uppercase tracking-wider text-faint">
Devices
@@ -97,43 +183,22 @@ export function DevicesSection({ source, onSelect, onError, onImport }: Props) {
)}
</div>
<div className="mt-1 px-2">
{list.map((d) => {
const isOpen = d.path === openPath
return (
<div key={d.path}>
<button
onClick={() =>
isOpen ? onSelect({ kind: 'device' }) : openDevice.mutate(d.path)
}
className={`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors ${
isOpen && source.kind === 'device'
? 'is-selected text-text'
: 'text-muted hover:bg-ink-800 hover:text-text'
}`}
>
<span className="flex w-4 justify-center text-gold"><Icon name="drive" size={15} /></span>
<span className="flex-1 truncate" title={d.path}>
{d.label}
</span>
{isOpen && open.data?.tracks != null && (
<span className="text-[10px] text-faint">{open.data.tracks}</span>
)}
</button>
<div className="mt-1 min-h-0 overflow-y-auto px-2 pb-1">
{external.map((d) => driveRow(d, 0))}
{isOpen &&
(playlists.data ?? []).map((n) => (
<DevicePlaylistRow
key={n.id}
node={n}
depth={1}
source={source}
onSelect={onSelect}
/>
))}
</div>
)
})}
{local.length > 0 && (
<>
<TreeRow
depth={0}
icon={<Icon name="desktop" size={15} />}
label="Local Storage"
expanded={localOpen}
onToggle={() => setRow(localKey, !localOpen)}
onClick={() => setRow(localKey, !localOpen)}
/>
{localOpen && local.map((d) => driveRow(d, 1))}
</>
)}
{openDevice.isPending && (
<div className="px-2 py-1.5 text-xs text-faint">Opening…</div>
@@ -147,10 +212,152 @@ export function DevicesSection({ source, onSelect, onError, onImport }: Props) {
</button>
)}
</div>
</div>
)
}
function isInside(path: string, root: string): boolean {
const r = root.endsWith('/') || root.endsWith('\\') ? root : `${root}/`
return path === root || path.startsWith(r) || path.startsWith(root + '\\')
}
/** Indent per level, capped so a deep folder still has room for its name. */
function indent(depth: number): number {
return 4 + Math.min(depth, 8) * 12
}
/** One row of the tree: a chevron that expands, and a label that acts. */
function TreeRow({
depth,
icon,
label,
title,
expanded,
onToggle,
onClick,
selected = false,
trailing,
}: {
depth: number
icon: ReactNode
label: string
title?: string
expanded: boolean
onToggle: () => void
onClick: () => void
selected?: boolean
trailing?: ReactNode
}) {
return (
<div
style={{ paddingLeft: indent(depth) }}
className={`flex w-full items-center gap-1 rounded-md py-1 pr-2 text-sm transition-colors ${
selected ? 'is-selected text-text' : 'text-muted hover:bg-ink-800 hover:text-text'
}`}
>
<button
aria-label={expanded ? 'Collapse' : 'Expand'}
onClick={onToggle}
className="flex h-4 w-4 shrink-0 items-center justify-center text-faint hover:text-text"
>
<Icon name={expanded ? 'chevronDown' : 'chevronRight'} size={12} />
</button>
<button onClick={onClick} title={title} className="flex min-w-0 flex-1 items-center gap-2 text-left">
<span className="flex w-4 shrink-0 justify-center">{icon}</span>
<span className="flex-1 truncate">{label}</span>
{trailing}
</button>
</div>
)
}
/**
* A folder in a Files tree. Clicking it shows its audio in the table (and
* expands it); the chevron only expands. Its subfolders are fetched the first
* time it opens, one level at a time.
*/
function FolderRow({
path,
name,
viewName,
icon,
depth,
source,
onSelect,
isOpenRow,
setRow,
}: {
path: string
name: string
/** What the table's header calls this folder, when not its own name. */
viewName?: string
icon: 'folder'
depth: number
source: Source
onSelect: (s: Source) => void
isOpenRow: (key: string) => boolean
setRow: (key: string, open: boolean) => void
}) {
const key = `folder:${path}`
const expanded = isOpenRow(key)
const children = useQuery({
queryKey: ['fs-folders', path],
queryFn: () => api.folders(path),
enabled: expanded,
staleTime: 10_000,
})
const selected = source.kind === 'folder' && source.path === path
return (
<>
<TreeRow
depth={depth}
icon={
<span className={selected ? 'text-accent' : 'text-faint'}>
<Icon name={expanded ? 'folderOpen' : icon} size={14} />
</span>
}
label={name}
title={path}
expanded={expanded}
onToggle={() => setRow(key, !expanded)}
onClick={() => {
setRow(key, true)
onSelect({ kind: 'folder', path, name: viewName ?? name })
}}
selected={selected}
/>
{expanded && (
<>
{children.isLoading && (
<div style={{ paddingLeft: indent(depth + 1) + 20 }} className="py-1 text-xs text-faint">
Loading…
</div>
)}
{children.isError && (
<div style={{ paddingLeft: indent(depth + 1) + 20 }} className="py-1 text-xs text-pink">
Can’t read this folder
</div>
)}
{(children.data ?? []).map((c) => (
<FolderRow
key={c.path}
path={c.path}
name={c.name}
icon="folder"
depth={depth + 1}
source={source}
onSelect={onSelect}
isOpenRow={isOpenRow}
setRow={setRow}
/>
))}
</>
)}
</>
)
}
/**
* A playlist on the device. Deliberately NOT `NodeRow`: that one carries rename
* and delete, and every one of a device's nodes reports those as false, so
@@ -176,7 +383,7 @@ function DevicePlaylistRow({
onClick={() =>
node.selectable && onSelect({ kind: 'device-playlist', id: node.id, name: node.name })
}
style={{ paddingLeft: 8 + depth * 12 }}
style={{ paddingLeft: indent(depth) + 20 }}
className={`flex w-full items-center gap-2 rounded-md py-1 pr-2 text-left text-sm transition-colors ${
selected
? 'is-selected text-text'
+17 -13
View File
@@ -8,6 +8,9 @@ import {
type GridMarker,
type Track,
type TrackCues,
type TrackOrigin,
trackAudioUrl,
trackCuesFor,
} from '../api'
import { buildBeatGrid, GRID_EPS } from '../lib/beatgrid'
import { slotLabeller, useCaps } from '../lib/capabilities'
@@ -36,12 +39,13 @@ interface Props {
/** Neutral/success feedback (e.g. Auto Hotcues result). */
onNotify?: (kind: 'success' | 'error', msg: string) => void
/**
* The track came from a browsed DEVICE, not the loaded library, so its audio
* and cues must be read from the source endpoints. Every EDIT control is
* already inert here — a device's capabilities say `writable: false`, and the
* deck gates on those — so this only needs to redirect the two READS.
* Which library the track belongs to, and so which endpoints serve its audio
* and cues: the loaded collection, a browsed DEVICE, or a browsed FOLDER of
* loose files. Every EDIT control is already inert for the last two — their
* capabilities say `writable: false`, and the deck gates on those — so this
* only needs to redirect the two READS.
*/
fromDevice?: boolean
origin?: TrackOrigin
/** Bumped when something outside the deck (batch grid analysis) rewrote the
* loaded track's cues/grid, so the deck re-reads them. */
cuesRefresh?: number
@@ -85,7 +89,7 @@ export function PrepStrip({
playRequest = 0,
onError,
onNotify,
fromDevice = false,
origin = 'collection',
cuesRefresh = 0,
}: Props) {
const qc = useQueryClient()
@@ -250,8 +254,8 @@ export function PrepStrip({
// Recolour the whole app from this track's cover art. A device's art is not
// served (only its audio is), so a device track keeps the default look.
useEffect(() => {
void setAmbientFromArt(trackId && !fromDevice ? api.artUrl(trackId) : null)
}, [trackId, fromDevice])
void setAmbientFromArt(trackId && origin === 'collection' ? api.artUrl(trackId) : null)
}, [trackId, origin])
// Analyse once per track; the decoded buffer feeds both the playback and
// scratch engines (no re-decode) and both waveform views share the columns.
@@ -266,7 +270,7 @@ export function PrepStrip({
let cancelled = false
setCols(null)
setWaveStatus('loading')
analyzeWaveform(fromDevice ? api.sourceAudioUrl(trackId) : api.audioUrl(trackId))
analyzeWaveform(trackAudioUrl(origin, trackId))
.then((res) => {
if (cancelled) return
setCols(res.cols)
@@ -297,7 +301,7 @@ export function PrepStrip({
return () => {
cancelled = true
}
}, [trackId, fromDevice])
}, [trackId, origin])
// Fetch beatgrid + cue markers for the loaded track.
useEffect(() => {
@@ -307,7 +311,7 @@ export function PrepStrip({
}
let cancelled = false
setCueData(null)
;(fromDevice ? api.sourceTrackCues(trackId) : api.trackCues(trackId))
;trackCuesFor(origin, trackId)
.then((d) => {
if (cancelled) return
setCueData(d)
@@ -322,7 +326,7 @@ export function PrepStrip({
return () => {
cancelled = true
}
}, [trackId, fromDevice])
}, [trackId, origin])
// Re-read after an outside edit. Deliberately NOT the effect above: that one
// resets `originalGridRef`, and "Reset" should still restore the grid the
@@ -1128,7 +1132,7 @@ export function PrepStrip({
<div className="glass flex h-[19.75rem] shrink-0 flex-col gap-2 p-4">
{/* ---- Header: the track, its readouts, the analysis actions ---- */}
<div className="flex h-12 shrink-0 items-center gap-3">
<CoverThumb trackId={track && !fromDevice ? track.id : null} />
<CoverThumb trackId={track && origin === 'collection' ? track.id : null} />
<div className="min-w-0 flex-1">
{track ? (
<>
+4 -1
View File
@@ -27,6 +27,9 @@ export type Source =
| { kind: 'playlist'; id: string; name: string }
| { kind: 'device' }
| { kind: 'device-playlist'; id: string; name: string }
// A folder of loose files on any drive, browsed from a Files tree. Its tracks
// are not in any library until added, so the view is read-only.
| { kind: 'folder'; path: string; name: string }
// An export set. `export` is its root — every track it would ship, deduped —
// and `export-playlist` is one referenced playlist inside it, read live from
// the library rather than from the set, which is the reference doing its job.
@@ -557,7 +560,7 @@ export function Sidebar({
{/* Right-click here (below the rows) creates at the top level; rows
stop the event so they get their own menu. */}
<div
className="mt-1 flex-1 overflow-y-auto px-2 pb-4"
className="mt-1 min-h-24 flex-1 overflow-y-auto px-2 pb-4"
onContextMenu={(e) => openMenu(e, createItems(null))}
>
{draft?.parentId === null && <DraftRow draft={draft} depth={0} actions={actions} />}
+12 -1
View File
@@ -11,6 +11,7 @@ import {
type VisibilityState,
} from '@tanstack/react-table'
import { useVirtualizer } from '@tanstack/react-virtual'
import { Icon } from '../lib/icons'
import { useCaps } from '../lib/capabilities'
import {
DndContext,
@@ -64,6 +65,9 @@ interface Props {
/** The row-number column shows these (a playlist's own 1-based positions)
* instead of the row's place in the current view. */
positions?: Map<string, number>
/** Rows to flag in the # column with a check and this tooltip — a browsed
* folder uses it for files the collection already holds. */
marked?: { ids: Set<string>; title: string }
/** A view with a manual order. `enabled` is false while a sort or filter is
* active: reordering a partial or re-sorted list would lose the real order. */
reorder?: { enabled: boolean; onReorder: (ids: string[]) => void }
@@ -263,6 +267,7 @@ export function TrackTable({
onColumnSizingChange,
selection,
positions,
marked,
reorder,
onRemove,
onRowContextMenu,
@@ -569,7 +574,13 @@ export function TrackTable({
}}
>
<span className="w-10 shrink-0 pr-2 text-right text-xs tabular-nums text-faint">
{positions?.get(row.original.id) ?? vr.index + 1}
{marked?.ids.has(row.original.id) ? (
<span title={marked.title} className="inline-flex text-mint">
<Icon name="check" size={13} />
</span>
) : (
(positions?.get(row.original.id) ?? vr.index + 1)
)}
</span>
{hasPlay && (
<span className="flex w-9 shrink-0 items-center justify-center">