mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Added device file exploration and file importing
This commit is contained in:
1 parent
b9d43dd7ea
commit
bd425f8cd6
18 files changed
+1819
-120
No files matched your search
+199
-29
@@ -3,7 +3,7 @@ import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import type { ColumnSizingState, SortingState, VisibilityState } from '@tanstack/react-table'
|
||||
import { CapabilitiesContext, slotLabeller } from './lib/capabilities'
|
||||
import { writeHint } from './lib/platformCopy'
|
||||
import { api, type CueBatchResult, type GridBatchResult, type AutoCueSlot, type PlaylistNode, type Track } from './api'
|
||||
import { api, type CueBatchResult, type GridBatchResult, type AutoCueSlot, type PlaylistNode, type Track, type TrackOrigin } from './api'
|
||||
import {
|
||||
COLUMN_MENU,
|
||||
DEFAULT_COLUMN_ORDER,
|
||||
@@ -24,6 +24,7 @@ import { PathMappingDialog } from './components/PathMappingDialog'
|
||||
import { HistoryPanel } from './components/HistoryPanel'
|
||||
import { PrepStrip } from './components/PrepStrip'
|
||||
import { ImportDialog } from './components/ImportDialog'
|
||||
import { AddFilesDialog, type AddTarget } from './components/AddFilesDialog'
|
||||
import { Icon } from './lib/icons'
|
||||
|
||||
function applyFilters(tracks: Track[], f: Filters): Track[] {
|
||||
@@ -63,6 +64,14 @@ export default function App() {
|
||||
const [showPaths, setShowPaths] = useState(false)
|
||||
const [showHistory, setShowHistory] = useState(false)
|
||||
const [prepTrack, setPrepTrack] = useState<Track | null>(null)
|
||||
// Which library the DECK's track came from — not the view's. Browsing to a
|
||||
// playlist while a device or folder track is loaded must not switch the deck
|
||||
// to endpoints that do not know that track.
|
||||
const [prepOrigin, setPrepOrigin] = useState<TrackOrigin>('collection')
|
||||
// The view's origin, read by the load callbacks below (defined before it).
|
||||
const viewOriginRef = useRef<TrackOrigin>('collection')
|
||||
// Browsed files being added to the collection (and maybe a playlist/export).
|
||||
const [adding, setAdding] = useState<{ ids: string[]; target: AddTarget | null } | null>(null)
|
||||
const [playRequest, setPlayRequest] = useState(0) // bump → deck loads & auto-plays
|
||||
const [importing, setImporting] = useState(false)
|
||||
// Batch analysis (grid, or Auto Hotcues): a confirm step, then the running
|
||||
@@ -79,10 +88,17 @@ export default function App() {
|
||||
// Every Remove ▸ action (and the playlist Delete key) confirms first.
|
||||
const [confirmReq, setConfirmReq] = useState<ConfirmRequest | null>(null)
|
||||
|
||||
const playTrack = useCallback((t: Track) => {
|
||||
const loadTrack = useCallback((t: Track) => {
|
||||
setPrepTrack(t)
|
||||
setPlayRequest((n) => n + 1)
|
||||
setPrepOrigin(viewOriginRef.current)
|
||||
}, [])
|
||||
const playTrack = useCallback(
|
||||
(t: Track) => {
|
||||
loadTrack(t)
|
||||
setPlayRequest((n) => n + 1)
|
||||
},
|
||||
[loadTrack],
|
||||
)
|
||||
|
||||
// ---- configurable library columns (persisted to userprefs.json) ----
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>(DEFAULT_COLUMN_VISIBILITY)
|
||||
@@ -250,9 +266,34 @@ export default function App() {
|
||||
const deviceCaps = useQuery({
|
||||
queryKey: ['source-capabilities'],
|
||||
queryFn: api.sourceCapabilities,
|
||||
enabled: viewingDevice,
|
||||
enabled: viewingDevice || prepOrigin === 'device',
|
||||
staleTime: Infinity,
|
||||
})
|
||||
|
||||
// A browsed folder of loose files. Read-only like a device, for the same
|
||||
// reason: its track ids (absolute paths) are not collection tracks.
|
||||
const viewingFolder = source.kind === 'folder'
|
||||
const folderPath = source.kind === 'folder' ? source.path : null
|
||||
const folderView = useQuery({
|
||||
queryKey: ['folder-tracks', folderPath],
|
||||
queryFn: () => api.folderTracks(folderPath!),
|
||||
enabled: loaded && viewingFolder,
|
||||
})
|
||||
const folderCaps = useQuery({
|
||||
queryKey: ['folder-capabilities', folderPath],
|
||||
queryFn: () => api.folderCapabilities(folderPath!),
|
||||
enabled: loaded && viewingFolder,
|
||||
staleTime: Infinity,
|
||||
})
|
||||
const heldInFolder = useMemo(
|
||||
() => new Set(folderView.data?.in_collection ?? []),
|
||||
[folderView.data],
|
||||
)
|
||||
viewOriginRef.current = viewingDevice ? 'device' : viewingFolder ? 'folder' : 'collection'
|
||||
// Tracks in view belong to ANOTHER library (a device) or to none (a folder),
|
||||
// so no collection command may be offered on them: their ids mean nothing to
|
||||
// the collection's routes.
|
||||
const viewForeign = viewingDevice || viewingFolder
|
||||
const openDevice = useQuery({ queryKey: ['source'], queryFn: api.source })
|
||||
const exportSets = useQuery({ queryKey: ['exports'], queryFn: api.exports, enabled: loaded })
|
||||
const playlists = useQuery({ queryKey: ['playlists'], queryFn: api.playlists, enabled: loaded })
|
||||
@@ -320,14 +361,21 @@ export default function App() {
|
||||
// browsing half of the UI gates itself correctly with no new conditions.
|
||||
// Falls back to the collection's until the device's resolve, so no frame
|
||||
// renders without capabilities at all.
|
||||
const viewCaps = viewingDevice
|
||||
? (deviceCaps.data ??
|
||||
// Until the device's own capabilities arrive, assume READ-ONLY rather
|
||||
// than falling back to the collection's. The fallback is the safe
|
||||
// direction on purpose: guessing "writable" for one frame would offer an
|
||||
// edit that, if taken, would be sent to the wrong library entirely.
|
||||
{ ...capabilities.data!, writable: false, readonly_cause: 'platform_incomplete' as const })
|
||||
: capabilities.data!
|
||||
// Until a device's or folder's own capabilities arrive, assume READ-ONLY
|
||||
// rather than falling back to the collection's. The fallback is the safe
|
||||
// direction on purpose: guessing "writable" for one frame would offer an edit
|
||||
// that, if taken, would be sent to the wrong library entirely.
|
||||
const readOnlyCaps = (cause: 'platform_incomplete' | 'not_in_library') =>
|
||||
capabilities.data ? { ...capabilities.data, writable: false, readonly_cause: cause } : capabilities.data!
|
||||
const capsFor = (origin: TrackOrigin) =>
|
||||
origin === 'device'
|
||||
? (deviceCaps.data ?? readOnlyCaps('platform_incomplete'))
|
||||
: origin === 'folder'
|
||||
? (folderCaps.data ?? readOnlyCaps('not_in_library'))
|
||||
: capabilities.data!
|
||||
const viewCaps = capsFor(viewOriginRef.current)
|
||||
// The deck follows its TRACK's library, not the view's.
|
||||
const deckCaps = capsFor(prepOrigin)
|
||||
|
||||
const deviceLabel = openDevice.data?.label ?? 'device'
|
||||
// One name for whatever is on screen, so the header and the status bar cannot
|
||||
@@ -340,7 +388,9 @@ export default function App() {
|
||||
: source.name
|
||||
|
||||
const isAll = source.kind === 'all'
|
||||
const tracks: Track[] = viewingDevice
|
||||
const tracks: Track[] = viewingFolder
|
||||
? (folderView.data?.tracks ?? [])
|
||||
: viewingDevice
|
||||
? source.kind === 'device'
|
||||
? (deviceTracks.data?.items ?? [])
|
||||
: (devicePlaylistTracks.data ?? [])
|
||||
@@ -353,7 +403,9 @@ export default function App() {
|
||||
: isAll
|
||||
? (allTracks.data?.items ?? [])
|
||||
: (playlistTracks.data ?? [])
|
||||
const loading = viewingDevice
|
||||
const loading = viewingFolder
|
||||
? folderView.isLoading
|
||||
: viewingDevice
|
||||
? source.kind === 'device'
|
||||
? deviceTracks.isLoading
|
||||
: devicePlaylistTracks.isLoading
|
||||
@@ -567,7 +619,7 @@ export default function App() {
|
||||
void runGridAnalysis(ids, false)
|
||||
}
|
||||
}
|
||||
const canAnalyzeGrid = canEdit && !viewingDevice && !!capabilities.data?.grid.editable
|
||||
const canAnalyzeGrid = canEdit && !viewForeign && !!capabilities.data?.grid.editable
|
||||
|
||||
const startCueBatch = (ids: string[]) => {
|
||||
const byId = new Map(tracks.map((t) => [t.id, t]))
|
||||
@@ -580,7 +632,7 @@ export default function App() {
|
||||
setBatchCancelling(false)
|
||||
setBatchJob({ id: job.id, kind: 'cues' })
|
||||
}
|
||||
const canAutoCue = canEdit && !viewingDevice && (capabilities.data?.cues.hotcue_slots ?? 0) > 0
|
||||
const canAutoCue = canEdit && !viewForeign && (capabilities.data?.cues.hotcue_slots ?? 0) > 0
|
||||
|
||||
// ---- Remove ▸ -----------------------------------------------------------
|
||||
const nTracks = (n: number) => `${n} track${n === 1 ? '' : 's'}`
|
||||
@@ -720,9 +772,9 @@ export default function App() {
|
||||
}),
|
||||
})
|
||||
|
||||
const canClearGrids = canEdit && !viewingDevice && !!capabilities.data?.grid.editable
|
||||
const canClearGrids = canEdit && !viewForeign && !!capabilities.data?.grid.editable
|
||||
const canClearCues = canAutoCue
|
||||
const canRemoveTracks = canEdit && !viewingDevice && !!capabilities.data?.tracks.removable
|
||||
const canRemoveTracks = canEdit && !viewForeign && !!capabilities.data?.tracks.removable
|
||||
const exportRootId =
|
||||
source.kind === 'export' ? source.id : source.kind === 'export-other' ? source.exportId : null
|
||||
const removeItems = (ids: string[]): MenuItem[] => [
|
||||
@@ -769,6 +821,23 @@ export default function App() {
|
||||
]
|
||||
}
|
||||
|
||||
// The same targets as "Add to", but each opens the add dialog: a loose file
|
||||
// has to join the collection before a playlist or export can hold it.
|
||||
const folderAddToItems = (ids: string[]): MenuItem[] => [
|
||||
{ heading: 'Playlists', empty: addablePlaylists.length ? undefined : 'No playlists' },
|
||||
...addablePlaylists.map((p) => ({
|
||||
label: p.name,
|
||||
hint: String(p.count),
|
||||
onClick: () => setAdding({ ids, target: { kind: 'playlist' as const, id: p.id, name: p.name } }),
|
||||
})),
|
||||
{ heading: 'Exports', empty: exportSets.data?.length ? undefined : 'No exports yet' },
|
||||
...(exportSets.data ?? []).map((set) => ({
|
||||
label: set.name,
|
||||
icon: <Icon name="export" size={13} />,
|
||||
onClick: () => setAdding({ ids, target: { kind: 'export' as const, id: set.id, name: set.name } }),
|
||||
})),
|
||||
]
|
||||
|
||||
return (
|
||||
<CapabilitiesContext.Provider value={capabilities.data!}>
|
||||
{/* Floating glass panels with gaps between them: the ambient backdrop
|
||||
@@ -785,11 +854,11 @@ export default function App() {
|
||||
items={[
|
||||
// Single-track actions are hidden, not disabled, for a multi-selection.
|
||||
...(menu.ids.length === 1
|
||||
? [{ label: 'Load to Deck', onClick: () => setPrepTrack(menu.track) }]
|
||||
? [{ label: 'Load to Deck', onClick: () => loadTrack(menu.track) }]
|
||||
: []),
|
||||
// Offering "Edit Tags…" on a read-only library would open a dialog
|
||||
// whose every save is refused, so it is not offered at all.
|
||||
...(canEdit && menu.ids.length === 1
|
||||
...(canEdit && !viewForeign && menu.ids.length === 1
|
||||
? [{ label: 'Edit Tags…', onClick: () => setEditing(menu.track) }]
|
||||
: []),
|
||||
...(canAnalyzeGrid
|
||||
@@ -815,8 +884,17 @@ export default function App() {
|
||||
]
|
||||
: []),
|
||||
// A device's track ids belong to the stick, not the collection, so
|
||||
// there is nothing they could be added to.
|
||||
...(viewingDevice ? [] : [{ label: 'Add to', submenu: addToItems(menu.ids) }]),
|
||||
// there is nothing they could be added to. A folder's files CAN be
|
||||
// added — through the add dialog, which puts them in the
|
||||
// collection first.
|
||||
...(viewingFolder
|
||||
? [
|
||||
{ label: 'Add to Collection…', onClick: () => setAdding({ ids: menu.ids, target: null }) },
|
||||
{ label: 'Add to', submenu: folderAddToItems(menu.ids) },
|
||||
]
|
||||
: viewingDevice
|
||||
? []
|
||||
: [{ label: 'Add to', submenu: addToItems(menu.ids) }]),
|
||||
...(() => {
|
||||
const items = removeItems(menu.ids)
|
||||
return items.length ? [{ label: 'Remove', submenu: items }] : []
|
||||
@@ -901,14 +979,27 @@ export default function App() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{adding && (
|
||||
<AddFilesDialog
|
||||
trackIds={adding.ids}
|
||||
target={adding.target}
|
||||
onClose={() => setAdding(null)}
|
||||
onDone={(msg) => {
|
||||
setAdding(null)
|
||||
notify('success', msg)
|
||||
}}
|
||||
onError={onError}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Prep strip spans the top of the window; the library sits below it. */}
|
||||
<CapabilitiesContext.Provider value={viewCaps}>
|
||||
<CapabilitiesContext.Provider value={deckCaps}>
|
||||
<PrepStrip
|
||||
track={prepTrack}
|
||||
playRequest={playRequest}
|
||||
onError={onError}
|
||||
onNotify={notify}
|
||||
fromDevice={viewingDevice}
|
||||
origin={prepOrigin}
|
||||
cuesRefresh={cuesRefresh}
|
||||
/>
|
||||
</CapabilitiesContext.Provider>
|
||||
@@ -932,20 +1023,61 @@ export default function App() {
|
||||
filters={filters}
|
||||
onChange={setFilters}
|
||||
/>
|
||||
{(!isAll || viewingDevice) && (
|
||||
{(!isAll || viewForeign) && (
|
||||
<div className="flex items-center gap-3 border-b border-line px-4 py-2">
|
||||
<span
|
||||
className={`flex ${
|
||||
viewingDevice ? 'text-gold' : viewingExport ? 'text-gold' : 'text-accent'
|
||||
viewingDevice || viewingFolder ? 'text-gold' : viewingExport ? 'text-gold' : 'text-accent'
|
||||
}`}
|
||||
>
|
||||
<Icon
|
||||
name={viewingDevice ? 'drive' : viewingExport && source.kind === 'export' ? 'export' : 'playlist'}
|
||||
name={
|
||||
viewingDevice
|
||||
? 'drive'
|
||||
: viewingFolder
|
||||
? 'folderOpen'
|
||||
: viewingExport && source.kind === 'export'
|
||||
? 'export'
|
||||
: 'playlist'
|
||||
}
|
||||
size={15}
|
||||
/>
|
||||
</span>
|
||||
<span className="font-semibold text-text">{viewName}</span>
|
||||
{viewingExport ? (
|
||||
<span className="font-semibold text-text" title={folderPath ?? undefined}>{viewName}</span>
|
||||
{viewingFolder ? (
|
||||
<>
|
||||
<span className="text-xs text-faint">
|
||||
{filtersActive
|
||||
? `${filtered.length} of ${tracks.length} files`
|
||||
: `${tracks.length} file${tracks.length === 1 ? '' : 's'}`}
|
||||
{heldInFolder.size > 0 && ` · ${heldInFolder.size} already in your collection`}
|
||||
{' · this folder only'}
|
||||
</span>
|
||||
<span className="ml-auto flex items-center gap-2">
|
||||
<span className="rounded-full bg-gold/10 px-2 py-0.5 text-[10px] uppercase tracking-wide text-gold shadow-[inset_0_0_0_1px_rgb(255_200_97/0.3)]">
|
||||
Not in collection
|
||||
</span>
|
||||
{tracks.length > 0 && (
|
||||
<button
|
||||
onClick={() =>
|
||||
setAdding({
|
||||
// The selection when there is one, else everything in
|
||||
// view that the collection does not already hold.
|
||||
ids: selected.size
|
||||
? filtered.filter((t) => selected.has(t.id)).map((t) => t.id)
|
||||
: filtered.filter((t) => !heldInFolder.has(t.id)).map((t) => t.id),
|
||||
target: null,
|
||||
})
|
||||
}
|
||||
disabled={!selected.size && filtered.every((t) => heldInFolder.has(t.id))}
|
||||
className="btn-primary rounded-full px-3 py-1 text-xs font-semibold disabled:opacity-40"
|
||||
>
|
||||
{selected.size ? `Add ${selected.size} to collection…` : 'Add all to collection…'}
|
||||
</button>
|
||||
)}
|
||||
</span>
|
||||
</>
|
||||
) : viewingExport ? (
|
||||
<>
|
||||
<span className="text-xs text-faint">
|
||||
{filtersActive
|
||||
@@ -1034,6 +1166,44 @@ export default function App() {
|
||||
onColumnSizingChange={setColumnSizing}
|
||||
/>
|
||||
)
|
||||
) : viewingFolder ? (
|
||||
/* A folder uses the plain table too, WITH selection: its bulk
|
||||
action is adding the selected files to the collection. The #
|
||||
column checks off the files the collection already holds. */
|
||||
folderView.isError ? (
|
||||
<div className="flex h-full flex-col items-center justify-center gap-1 text-muted">
|
||||
<div className="text-lg">Can’t read this folder</div>
|
||||
<div className="text-sm text-faint">{(folderView.error as Error).message}</div>
|
||||
</div>
|
||||
) : filtered.length === 0 ? (
|
||||
<div className="flex h-full flex-col items-center justify-center gap-1 text-muted">
|
||||
<div className="text-lg">
|
||||
{tracks.length === 0 ? 'No music here' : 'No tracks match'}
|
||||
</div>
|
||||
<div className="text-sm text-faint">
|
||||
{tracks.length === 0
|
||||
? 'This folder has no audio files directly in it — try one of its subfolders.'
|
||||
: 'Try clearing some filters.'}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<TrackTable
|
||||
tracks={filtered}
|
||||
sorting={sorting}
|
||||
onSortingChange={setSorting}
|
||||
selection={{ selected, onChange: setSelected }}
|
||||
marked={{ ids: heldInFolder, title: 'Already in your collection' }}
|
||||
onRowContextMenu={(track, x, y) => openMenu(track, x, y, true)}
|
||||
onHeaderContextMenu={(x, y) => setHeaderMenu({ x, y })}
|
||||
onPlay={playTrack}
|
||||
activeTrackId={prepTrack?.id ?? null}
|
||||
columnVisibility={columnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
columnSizing={columnSizing}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
onColumnSizingChange={setColumnSizing}
|
||||
/>
|
||||
)
|
||||
) : viewingDevice ? (
|
||||
/* A device uses the plain table, not the playlist one: a stick's
|
||||
playlists cannot be reordered or have entries removed, so the
|
||||
|
||||
+76
-1
@@ -223,7 +223,7 @@ export interface SaveCapabilities {
|
||||
}
|
||||
|
||||
/** Why a library cannot be edited. A fact — lib/platformCopy.ts words it. */
|
||||
export type ReadonlyCause = 'platform_incomplete' | 'cloud_synced'
|
||||
export type ReadonlyCause = 'platform_incomplete' | 'cloud_synced' | 'not_in_library'
|
||||
|
||||
export interface Capabilities {
|
||||
platform: Platform
|
||||
@@ -245,6 +245,8 @@ export interface Capabilities {
|
||||
media_kinds: MediaKind[]
|
||||
/** Tracks can be removed from the library (audio files are never touched). */
|
||||
removable: boolean
|
||||
/** Lower-case suffixes this library can hold — what a browsed folder lists. */
|
||||
audio_formats: string[]
|
||||
artwork: boolean
|
||||
artwork_note: string | null
|
||||
}
|
||||
@@ -335,6 +337,9 @@ export interface ImportPreview {
|
||||
missing: string[]
|
||||
/** Titles the collection already has by filename. A warning, not a block. */
|
||||
duplicates: string[]
|
||||
/** Titles whose exact FILE the collection already holds: not added again,
|
||||
* but still put in the playlist/export being added to. */
|
||||
existing: string[]
|
||||
playlists: string[]
|
||||
total_bytes: number
|
||||
destination: string | null
|
||||
@@ -342,6 +347,43 @@ export interface ImportPreview {
|
||||
enough_space: boolean | null
|
||||
}
|
||||
|
||||
// ---- drives and folders ----
|
||||
//
|
||||
// The sidebar's Devices and Local Storage trees. A browsed folder is read-only
|
||||
// and is not a library: its files are projected as tracks (id = absolute path)
|
||||
// so the ordinary table and deck show them, and adding goes through import.
|
||||
|
||||
export interface Drive {
|
||||
name: string
|
||||
path: string
|
||||
/** `local` = boot disk or a drive built in; anything uncertain is external. */
|
||||
kind: 'local' | 'external'
|
||||
/** The OneLibrary library on this drive, if it carries one. */
|
||||
library: SourceCandidate | null
|
||||
}
|
||||
|
||||
export interface FolderTracks {
|
||||
path: string
|
||||
tracks: Track[]
|
||||
/** Ids of the files the collection already points at. */
|
||||
in_collection: string[]
|
||||
/** On an external drive — referencing in place would go missing on unplug. */
|
||||
removable: boolean
|
||||
}
|
||||
|
||||
export interface FolderAddRequest {
|
||||
track_ids: string[]
|
||||
mode: 'copy' | 'reference'
|
||||
/** Required for `copy`. */
|
||||
destination?: string | null
|
||||
playlist_id?: string | null
|
||||
export_id?: string | null
|
||||
}
|
||||
|
||||
export interface FolderAddPreview extends ImportPreview {
|
||||
removable: boolean
|
||||
}
|
||||
|
||||
export type JobState = 'running' | 'done' | 'failed' | 'cancelled'
|
||||
|
||||
export interface JobStatus {
|
||||
@@ -770,6 +812,20 @@ export const api = {
|
||||
/** Audition a track off the stick before importing it. */
|
||||
sourceAudioUrl: (trackId: string) =>
|
||||
`${API_BASE}/api/source/tracks/audio?track_id=${encodeURIComponent(trackId)}`,
|
||||
// ---- drives and folders ----
|
||||
drives: () => getJSON<Drive[]>('/api/fs/drives'),
|
||||
folders: (path: string) => getJSON<FsEntry[]>(`/api/fs/folders?path=${encodeURIComponent(path)}`),
|
||||
folderTracks: (path: string) =>
|
||||
getJSON<FolderTracks>(`/api/folder/tracks?path=${encodeURIComponent(path)}`),
|
||||
folderCapabilities: (path: string) =>
|
||||
getJSON<Capabilities>(`/api/folder/capabilities?path=${encodeURIComponent(path)}`),
|
||||
folderTrackCues: (trackId: string) =>
|
||||
getJSON<TrackCues>(`/api/folder/tracks/cues?track_id=${encodeURIComponent(trackId)}`),
|
||||
folderAudioUrl: (trackId: string) =>
|
||||
`${API_BASE}/api/folder/tracks/audio?track_id=${encodeURIComponent(trackId)}`,
|
||||
folderAddPreview: (body: FolderAddRequest) =>
|
||||
send<FolderAddPreview>('POST', '/api/folder/add/preview', body),
|
||||
folderAdd: (body: FolderAddRequest) => send<JobStatus>('POST', '/api/folder/add', body),
|
||||
// ---- import ----
|
||||
importPreview: (body: ImportRequest) => send<ImportPreview>('POST', '/api/import/preview', body),
|
||||
/** Starts the job and returns immediately — poll `job()` for progress. */
|
||||
@@ -788,3 +844,22 @@ export const api = {
|
||||
return res.json()
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Which library a track in view belongs to. Ids are only unique WITHIN one —
|
||||
* a device's track and a collection track can share an id — so anything that
|
||||
* fetches by id must know which one it is asking.
|
||||
*/
|
||||
export type TrackOrigin = 'collection' | 'device' | 'folder'
|
||||
|
||||
export function trackAudioUrl(origin: TrackOrigin, trackId: string): string {
|
||||
if (origin === 'device') return api.sourceAudioUrl(trackId)
|
||||
if (origin === 'folder') return api.folderAudioUrl(trackId)
|
||||
return api.audioUrl(trackId)
|
||||
}
|
||||
|
||||
export function trackCuesFor(origin: TrackOrigin, trackId: string): Promise<TrackCues> {
|
||||
if (origin === 'device') return api.sourceTrackCues(trackId)
|
||||
if (origin === 'folder') return api.folderTrackCues(trackId)
|
||||
return api.trackCues(trackId)
|
||||
}
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
@@ -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 ? (
|
||||
<>
|
||||
|
||||
@@ -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} />}
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -53,6 +53,8 @@ export function readOnlyNotice(caps: Capabilities): string | null {
|
||||
switch (caps.readonly_cause) {
|
||||
case 'cloud_synced':
|
||||
return `This ${caps.save.app_name} library is synced with ${caps.save.app_name} Cloud, so Konduktor will not write to it — an edit it did not make could break syncing on your other devices.`
|
||||
case 'not_in_library':
|
||||
return 'This file is not in your collection yet — add it to edit its tags, cues or beatgrid.'
|
||||
case 'platform_incomplete':
|
||||
default:
|
||||
return `Konduktor can read ${caps.save.app_name} libraries but cannot save changes to them yet.`
|
||||
@@ -62,6 +64,7 @@ export function readOnlyNotice(caps: Capabilities): string | null {
|
||||
/** Compact form for a badge or a disabled control's tooltip. */
|
||||
export function readOnlyShort(caps: Capabilities): string | null {
|
||||
if (caps.writable) return null
|
||||
if (caps.readonly_cause === 'not_in_library') return 'Not in collection'
|
||||
return caps.readonly_cause === 'cloud_synced' ? 'Read-only · cloud-synced' : 'Read-only'
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user