Added support for remote file exploring

This commit is contained in:
patben8 committed 2026-10-12 09:23:34 +02:00
1 parent 966f3fe8c5
commit 40630ff78e
18 files changed
+717 -70

No files matched your search

+92 -27
View File
@@ -8,6 +8,7 @@ import { addTracksToPlaylist } from './lib/addTracks'
import { useDropTarget } from './lib/drag'
import { api, type AnalyzeOptions, type AnalyzeResult, type CueBatchResult, type AutoCueSlot, type PlaylistNode, type StemBatchResult, type Track, type TrackOrigin } from './api'
import { confirmDiscardUnsaved } from './lib/unsaved'
import { askConfirm } from './lib/confirm'
import {
COLUMN_MENU,
DEFAULT_COLUMN_ORDER,
@@ -80,6 +81,9 @@ export default function App() {
const [prepOrigin, setPrepOrigin] = useState<TrackOrigin>('collection')
// The view's origin, read by the load callbacks below (defined before it).
const viewOriginRef = useRef<TrackOrigin>('collection')
// The browsed folder's rows that ARE collection tracks: collection id → the
// file's folder id. A ref, for the callbacks below that outlive a render.
const folderFilesRef = useRef<Record<string, string>>({})
// 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
@@ -108,7 +112,9 @@ export default function App() {
const loadTrack = useCallback((t: Track, origin: TrackOrigin = viewOriginRef.current) => {
setPrepTrack(t)
setPrepOrigin(origin)
// A folder row the collection holds IS the collection track, so the deck
// loads it as one: its cues and grid, and editable (decided 2026-10-10).
setPrepOrigin(origin === 'folder' && folderFilesRef.current[t.id] ? 'collection' : origin)
}, [])
const playTrack = useCallback(
(t: Track) => {
@@ -307,6 +313,11 @@ export default function App() {
() => new Set(folderView.data?.in_collection ?? []),
[folderView.data],
)
const folderFiles = useMemo(() => folderView.data?.files ?? {}, [folderView.data])
folderFilesRef.current = viewingFolder ? folderFiles : {}
// Adding speaks in FOLDER ids; a row the collection holds carries its
// collection id, and maps back (the add dialog then reports it as held).
const toFolderIds = (ids: string[]) => ids.map((id) => folderFiles[id] ?? id)
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
@@ -368,10 +379,16 @@ export default function App() {
// asked (decided 2026-10-06).
const addForeign = useCallback(
(origin: TrackOrigin, ids: string[], target: AddTarget) => {
if (origin === 'folder') setAdding({ ids, target })
else if (origin === 'device') setImportDrop({ ids, target })
if (origin === 'folder') {
const files = folderFilesRef.current
// Rows that are all collection tracks already: nothing to add first.
if (ids.every((id) => files[id])) {
if (target.kind === 'playlist') void addToPlaylist(target.id, ids)
else void addToExport(target.id, ids)
} else setAdding({ ids: ids.map((id) => files[id] ?? id), target })
} else if (origin === 'device') setImportDrop({ ids, target })
},
[],
[addToPlaylist, addToExport],
)
const [deckDropRef, deckOver] = useDropTarget<true>({
hint: (p) => (p.kind === 'tracks' ? true : null),
@@ -407,7 +424,10 @@ export default function App() {
: origin === 'folder'
? (folderCaps.data ?? readOnlyCaps('not_in_library'))
: capabilities.data!
const viewCaps = capsFor(viewOriginRef.current)
// A folder's table runs on the COLLECTION's: the rows it holds are collection
// tracks and edit as such, and a loose row asks to be added first
// (`folderMayEdit`) rather than rendering inert.
const viewCaps = viewingFolder ? capabilities.data! : capsFor(viewOriginRef.current)
// The deck follows its TRACK's library, not the view's.
const deckCaps = capsFor(prepOrigin)
@@ -443,9 +463,12 @@ export default function App() {
// PrepStrip keys its audio on the id, so a new object for the same id
// reloads nothing.
useEffect(() => {
if (!prepTrack || viewOriginRef.current !== prepOrigin) return
if (!prepTrack) return
const fresh = tracks.find((t) => t.id === prepTrack.id)
if (fresh && JSON.stringify(fresh) !== JSON.stringify(prepTrack)) setPrepTrack(fresh)
if (!fresh) return
const origin =
viewOriginRef.current === 'folder' && folderFilesRef.current[fresh.id] ? 'collection' : viewOriginRef.current
if (origin === prepOrigin && JSON.stringify(fresh) !== JSON.stringify(prepTrack)) setPrepTrack(fresh)
// Only a refetch of the list matters; prepTrack is read, not tracked.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tracks])
@@ -636,7 +659,7 @@ export default function App() {
}
// ---- Convert to Stems ------------------------------------------------------
const canStems = canEdit && !viewForeign && !!capabilities.data?.tracks.stem_convertible
const canStems = canEdit && !viewingDevice && !!capabilities.data?.tracks.stem_convertible
const finishStemBatch = (state: string, r: StemBatchResult | null, error: string | null) => {
qc.invalidateQueries({ queryKey: ['state'] })
if (state === 'failed' || !r) {
@@ -788,7 +811,7 @@ export default function App() {
// the rest with a reason.
const canAnalyzeGrid = !!capabilities.data?.grid.editable
const canAnalyzeKey = !!capabilities.data?.tracks.key_writable
const canAnalyze = canEdit && !viewForeign && (canAnalyzeGrid || canAnalyzeKey)
const canAnalyze = canEdit && !viewingDevice && (canAnalyzeGrid || canAnalyzeKey)
const startCueBatch = (ids: string[]) => {
const byId = new Map(tracks.map((t) => [t.id, t]))
@@ -801,7 +824,7 @@ export default function App() {
setBatchCancelling(false)
setBatchJob({ id: job.id, kind: 'cues' })
}
const canAutoCue = canEdit && !viewForeign && (capabilities.data?.cues.hotcue_slots ?? 0) > 0
const canAutoCue = canEdit && !viewingDevice && (capabilities.data?.cues.hotcue_slots ?? 0) > 0
// ---- Remove ▸ -----------------------------------------------------------
@@ -934,12 +957,48 @@ export default function App() {
}),
})
const canClearGrids = canEdit && !viewForeign && !!capabilities.data?.grid.editable
const canClearGrids = canEdit && !viewingDevice && !!capabilities.data?.grid.editable
const canClearCues = canAutoCue
const canRemoveTracks = canEdit && !viewForeign && !!capabilities.data?.tracks.removable
const canRemoveTracks = canEdit && !viewingDevice && !!capabilities.data?.tracks.removable
// The COLLECTION's capabilities, deliberately: adding happens while a folder
// or device is on screen, whose own capabilities are read-only.
const canAddTracks = canEdit && !!capabilities.data?.tracks.addable
// In a folder, only the rows the collection holds can be edited. Anything
// that would edit a loose file says so and offers to add it, rather than
// being absent or silently inert (decided 2026-10-10).
const askToAdd = async (ids: string[]) => {
const loose = ids.filter((id) => !folderFiles[id])
if (!loose.length) return
const first = tracks.find((t) => t.id === loose[0])
const what =
loose.length === 1
? `“${first?.title || 'This file'}” is not in your collection`
: `${loose.length} of these files are not in your collection`
if (!canAddTracks) {
notify('error', `${what}, and tracks cannot be added to this library.`)
return
}
const add = await askConfirm({
title: 'Add to your collection first',
body: `${what} yet. Add ${loose.length === 1 ? 'it' : 'them'} to edit tags, cues or the beatgrid.`,
confirmLabel: 'Add to Collection…',
tone: 'primary',
})
if (add) setAdding({ ids: loose, target: null })
}
const folderEditField = (track: Track, field: keyof Track, value: string | number) => {
if (folderFiles[track.id]) editField(track, field, value)
else void askToAdd([track.id])
}
const folderMayEdit = (track: Track) => {
if (folderFiles[track.id]) return true
void askToAdd([track.id])
return false
}
// The open menu's loose files: every editing item then asks to add them.
const menuLoose = menu && viewingFolder ? menu.ids.filter((id) => !folderFiles[id]) : []
const gated = (fn: () => void) => (menuLoose.length ? () => void askToAdd(menuLoose) : fn)
const exportRootId =
source.kind === 'export' ? source.id : source.kind === 'export-other' ? source.exportId : null
const removeItems = (ids: string[]): MenuItem[] => [
@@ -1023,8 +1082,8 @@ export default function App() {
: []),
// 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 && !viewForeign && menu.ids.length === 1
? [{ label: 'Edit Tags…', onClick: () => setEditing(menu.track) }]
...(canEdit && !viewingDevice && menu.ids.length === 1
? [{ label: 'Edit Tags…', onClick: gated(() => setEditing(menu.track)) }]
: []),
...(canAnalyze
? [
@@ -1032,7 +1091,7 @@ export default function App() {
label: 'Analyze…',
hint: batchJob ? 'busy' : menu.ids.length > 1 ? String(menu.ids.length) : undefined,
disabled: !!batchJob,
onClick: () => setAnalyzing(menu.ids),
onClick: gated(() => setAnalyzing(menu.ids)),
},
]
: []),
@@ -1044,20 +1103,20 @@ export default function App() {
label: 'Auto Hotcues…',
hint: batchJob ? 'busy' : menu.ids.length > 1 ? String(menu.ids.length) : undefined,
disabled: !!batchJob,
onClick: () => startCueBatch(menu.ids),
onClick: gated(() => startCueBatch(menu.ids)),
},
]
: []),
// Shown disabled WITH a reason where the platform cannot play stem
// files as stems, rather than hidden: a missing item reads as a bug.
...(canEdit && !viewForeign
...(canEdit && !viewingDevice
? [
canStems
? {
label: 'Convert to Stems…',
hint: batchJob ? 'busy' : menu.ids.length > 1 ? String(menu.ids.length) : undefined,
disabled: !!batchJob,
onClick: () => setStemDialog(menu.ids),
onClick: gated(() => setStemDialog(menu.ids)),
}
: {
label: 'Convert to Stems…',
@@ -1070,12 +1129,14 @@ 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. A folder's files CAN be
// added — through the add dialog, which puts them in the
// collection first.
// collection first; rows it already holds are collection tracks.
...(viewingFolder
? canAddTracks
? !menuLoose.length
? [{ label: 'Add to', submenu: addToItems(menu.ids) }]
: canAddTracks
? [
{ label: 'Add to Collection…', onClick: () => setAdding({ ids: menu.ids, target: null }) },
{ label: 'Add to', submenu: folderAddToItems(menu.ids) },
{ label: 'Add to Collection…', onClick: () => setAdding({ ids: menuLoose, target: null }) },
{ label: 'Add to', submenu: folderAddToItems(toFolderIds(menu.ids)) },
]
: [{
label: 'Add to Collection…',
@@ -1092,7 +1153,7 @@ export default function App() {
? [{ label: 'Set Position…', onClick: () => setPositioning(menu.ids) }]
: []),
...(() => {
const items = removeItems(menu.ids)
const items = menuLoose.length ? [] : removeItems(menu.ids)
return items.length ? [{ label: 'Remove', submenu: items }] : []
})(),
]}
@@ -1315,9 +1376,11 @@ export default function App() {
{' · 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 > heldInFolder.size && (
<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 && canAddTracks && (
<button
onClick={() =>
@@ -1325,7 +1388,7 @@ export default function App() {
// 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)
? toFolderIds(filtered.filter((t) => selected.has(t.id)).map((t) => t.id))
: filtered.filter((t) => !heldInFolder.has(t.id)).map((t) => t.id),
target: null,
})
@@ -1459,6 +1522,8 @@ export default function App() {
onRowContextMenu={(track, x, y) => openMenu(track, x, y, true)}
onHeaderContextMenu={(x, y) => setHeaderMenu({ x, y })}
onPlay={playTrack}
onEditField={canEdit ? folderEditField : undefined}
mayEdit={folderMayEdit}
activeTrackId={prepTrack?.id ?? null}
activePlaying={deckPlaying}
columnVisibility={columnVisibility}
+14 -3
View File
@@ -478,17 +478,28 @@ export interface ImportPreview {
export interface Drive {
name: string
path: string
/** `local` = boot disk or a drive built in; anything uncertain is external. */
kind: 'local' | 'external'
/** `local` = boot disk or a drive built in; anything uncertain is external.
* `server` = a remote library's content folder (path `server:`). */
kind: 'local' | 'external' | 'server'
/** The OneLibrary library on this drive, if it carries one. */
library: SourceCandidate | null
}
/** A path in a remote library's content folder, as the Files routes take it:
* `server:` + the path ON THE SERVER, so it cannot be taken for the same
* path on this computer. Such files are already where the library can reach
* them, so adding one never copies or uploads it. */
export const isServerPath = (path: string) => path.startsWith('server:')
export interface FolderTracks {
path: string
tracks: Track[]
/** Ids of the files the collection already points at. */
/** Collection ids of the rows that ARE collection tracks: a file the
* collection holds is listed as its track (id, key, rating, cues…), so it
* plays, edits and drags as one. Any other file is its own tags, id = path. */
in_collection: string[]
/** Those rows' collection id → the file's folder id, which adding takes. */
files: Record<string, string>
/** On an external drive — referencing in place would go missing on unplug. */
removable: boolean
}
+20 -6
View File
@@ -1,7 +1,7 @@
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 { api, isServerPath, type FolderAddPreview, type FolderAddRequest, type JobStatus } from '../api'
import { useCaps } from '../lib/capabilities'
import { placedAudioSummary } from '../lib/platformCopy'
import { FolderPicker } from './FolderPicker'
@@ -20,7 +20,10 @@ import { FolderPicker } from './FolderPicker'
*
* A library held by a server (`tracks.audio_destination === 'library'`) is the
* other exception: it cannot see this computer's files, so the only choice is
* which folder ON THE SERVER they are uploaded into.
* which folder ON THE SERVER they are uploaded into — unless the files were
* browsed in that server's own content folder: they are already where the
* library can reach them, so they are added in place, uploaded nowhere and
* nothing asked (decided 2026-10-10).
*
* 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
@@ -57,11 +60,15 @@ export function AddFilesDialog({ trackIds, target, onClose, onDone, onError }: P
// decides copy vs in place itself, so there is nothing to ask.
const caps = useCaps()
const places = caps.tracks.places_audio
// Already in the server's content folder: added where they are.
const onServer = trackIds.length > 0 && trackIds.every(isServerPath)
// Uploaded into a folder on the server: nothing to ask but where.
const uploads = !places && caps.tracks.audio_destination === 'library'
const [mode, setMode] = useState<'copy' | 'reference' | null>(uploads ? 'copy' : null)
const uploads = !places && !onServer && caps.tracks.audio_destination === 'library'
const [mode, setMode] = useState<'copy' | 'reference' | null>(
onServer ? 'reference' : uploads ? 'copy' : null,
)
const [folder, setFolder] = useState('')
const remote = useServerImportFolder(uploads)
const remote = useServerImportFolder(uploads || onServer)
const [browsing, setBrowsing] = useState(false)
const [job, setJob] = useState<JobStatus | null>(null)
const [starting, setStarting] = useState(false)
@@ -251,7 +258,14 @@ export function AddFilesDialog({ trackIds, target, onClose, onDone, onError }: P
</div>
)}
{!places && !uploads && (
{onServer && (
<div className="rounded well px-3 py-2 text-xs text-muted">
Already on {remote.serverName}, so your collection points at them where they
are. Nothing is uploaded or copied.
</div>
)}
{!places && !uploads && !onServer && (
<div className="space-y-1">
{option(
'copy',
+13 -5
View File
@@ -1,13 +1,14 @@
import { useEffect, useState, type ReactNode } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type Drive, type PlaylistNode } from '../api'
import { api, isServerPath, type Drive, type PlaylistNode } from '../api'
import type { Source } from './Sidebar'
import { Icon } from '../lib/icons'
import { ContextMenu, type MenuItem } from './ContextMenu'
/**
* Every drive, in the sidebar: plugged-in ones under Devices, and the computer's
* own under an expandable Local Storage.
* own under an expandable Local Storage. While a remote library is open, the
* server holding it comes first: its content folder, browsed like any drive.
*
* 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
@@ -86,13 +87,15 @@ export function DevicesSection({ source, onSelect, onError, onImport, onOpenLibr
})
const list = drives.data ?? []
const server = list.filter((d) => d.kind === 'server')
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. The same goes for a
// folder on it being browsed.
// folder on it being browsed — and for a folder on the server, the remote
// library being closed.
const stillPresent = !openPath || list.some((d) => d.library?.path === openPath)
useEffect(() => {
if (!drives.isSuccess || !openPath || stillPresent || eject.isPending) return
@@ -102,7 +105,11 @@ export function DevicesSection({ source, onSelect, onError, onImport, onOpenLibr
const folderGone =
source.kind === 'folder' &&
drives.isSuccess &&
!list.some((d) => d.path === '/' || isInside(source.path, d.path))
!list.some((d) =>
isServerPath(source.path)
? d.kind === 'server'
: d.path === '/' || isInside(source.path, d.path),
)
useEffect(() => {
if (folderGone) onSelect({ kind: 'all' })
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -137,7 +144,7 @@ export function DevicesSection({ source, onSelect, onError, onImport, onOpenLibr
<div key={d.path}>
<TreeRow
depth={depth}
icon={<span className="text-gold"><Icon name="drive" size={15} /></span>}
icon={<span className="text-gold"><Icon name={d.kind === 'server' ? 'server' : 'drive'} size={15} /></span>}
label={d.name}
title={d.path}
expanded={expandedHere}
@@ -212,6 +219,7 @@ export function DevicesSection({ source, onSelect, onError, onImport, onOpenLibr
</div>
<div className="mt-1 min-h-0 overflow-y-auto px-2 pb-1">
{server.map((d) => driveRow(d, 0))}
{external.map((d) => driveRow(d, 0))}
{local.length > 0 && (
+4 -1
View File
@@ -82,6 +82,8 @@ interface Props {
onHeaderContextMenu?: (x: number, y: number) => void
onPlay?: (track: Track) => void
onEditField?: (track: Track, field: keyof Track, value: string | number) => void
/** Per-row gate on opening an inline editor (`TableMeta.mayEdit`). */
mayEdit?: (track: Track) => boolean
activeTrackId?: string | null
/** Whether the deck is playing `activeTrackId` (vs. loaded but paused). */
activePlaying?: boolean
@@ -287,6 +289,7 @@ export function TrackTable({
onHeaderContextMenu,
onPlay,
onEditField,
mayEdit,
activeTrackId,
activePlaying = false,
}: Props) {
@@ -299,7 +302,7 @@ export function TrackTable({
data,
columns: TRACK_COLUMNS,
state: { sorting, columnVisibility, columnOrder, columnSizing },
meta: { onEditField, editableFields },
meta: { onEditField, editableFields, mayEdit },
onSortingChange: (updater) =>
onSortingChange(typeof updater === 'function' ? updater(sorting) : updater),
onColumnSizingChange: (updater) =>
+17
View File
@@ -29,6 +29,10 @@ declare module '@tanstack/react-table' {
* platforms genuinely differ in WHICH fields they accept. Undefined means
* "not gated" — every field with a handler stays editable. */
editableFields?: ReadonlySet<string>
/** Asked before an inline editor opens on a row; false keeps it closed.
* A view mixing editable rows with others (a folder: collection tracks
* beside loose files) answers per row — and says why itself. */
mayEdit?: (track: Track) => boolean
}
}
@@ -42,6 +46,7 @@ function InlineEdit({
onCommit,
className = 'w-full min-w-0 truncate text-muted',
readOnly = false,
onBegin,
}: {
value: string | null
display?: ReactNode
@@ -49,6 +54,8 @@ function InlineEdit({
className?: string
/** Render the value without offering an editor. */
readOnly?: boolean
/** Asked on double-click; false keeps the editor closed. */
onBegin?: () => boolean
}) {
const [editing, setEditing] = useState(false)
const [val, setVal] = useState('')
@@ -91,6 +98,7 @@ function InlineEdit({
<div
onDoubleClick={(e) => {
e.stopPropagation()
if (onBegin && !onBegin()) return
setVal(value ?? '')
setEditing(true)
}}
@@ -102,6 +110,11 @@ function InlineEdit({
)
}
/** Whether this row's editor may open (`TableMeta.mayEdit`). */
function mayBegin(c: CellContext<Track, unknown>): boolean {
return c.table.options.meta?.mayEdit?.(c.row.original) ?? true
}
/** Whether this table may edit `field`, per the platform's capabilities. */
function canEdit(c: CellContext<Track, unknown>, field: string): boolean {
const meta = c.table.options.meta
@@ -116,6 +129,7 @@ function editable(field: keyof Track, className?: string) {
value={c.getValue() as string | null}
className={className}
readOnly={!canEdit(c, field)}
onBegin={() => mayBegin(c)}
onCommit={(v) => c.table.options.meta?.onEditField?.(c.row.original, field, v)}
/>
)
@@ -137,12 +151,14 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
display={title || <span className="text-faint">Untitled</span>}
className="w-full min-w-0 truncate font-medium text-text group-data-[active]:text-accent"
readOnly={!canEdit(c, 'title')}
onBegin={() => mayBegin(c)}
onCommit={(v) => edit?.(r, 'title', v)}
/>
<InlineEdit
value={r.artist}
className="w-full min-w-0 truncate text-xs text-muted"
readOnly={!canEdit(c, 'artist')}
onBegin={() => mayBegin(c)}
onCommit={(v) => edit?.(r, 'artist', v)}
/>
</div>
@@ -310,6 +326,7 @@ export const TRACK_COLUMNS: ColumnDef<Track, any>[] = [
value={c.getValue() as string | null}
display={<span className="tabular-nums text-muted">{formatDate(c.getValue() as string | null)}</span>}
readOnly={!canEdit(c, 'release_date')}
onBegin={() => mayBegin(c)}
onCommit={(v) => c.table.options.meta?.onEditField?.(c.row.original, 'release_date', v)}
/>
),
+2
View File
@@ -11,6 +11,8 @@ const TRACK_LIST_KEYS = [
['export-tracks'],
['export-playlist-tracks'],
['export-loose'],
// A folder lists the files the collection holds AS collection tracks.
['folder-tracks'],
] as const
/** Refetch every collection track list, plus the unsaved-edits state. */