mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Improved drag to import dialog
This commit is contained in:
1 parent
bf427a628e
commit
518542c7bb
15 files changed
+180
-35
No files matched your search
@@ -32,7 +32,10 @@ import { FolderPicker } from './FolderPicker'
|
||||
* 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.
|
||||
* go into the target. A PLAYLIST target can be unticked (`usePlaylistToggle`,
|
||||
* on each time, never remembered — decided 2026-10-17): a drop on a playlist
|
||||
* is usually meant for it, but a drop on its open table may only be "into
|
||||
* the collection" aimed loosely.
|
||||
*/
|
||||
|
||||
const POLL_MS = 300
|
||||
@@ -47,6 +50,25 @@ export interface AddTarget {
|
||||
kind: 'playlist' | 'export'
|
||||
id: string
|
||||
name: string
|
||||
/** A playlist: insert at this position among its entries (a drop between
|
||||
* its rows); absent appends. */
|
||||
index?: number | null
|
||||
}
|
||||
|
||||
/** The add dialogs' "Also add to <playlist>" tick: on, unless unticked this
|
||||
* time. Answers the target actually in force (null = the collection only).
|
||||
* Exports have no tick — "Add to export" is the whole of that gesture. */
|
||||
export function usePlaylistToggle(requested: AddTarget | null | undefined) {
|
||||
const [on, setOn] = useState(true)
|
||||
const offered = requested?.kind === 'playlist'
|
||||
const target = offered && !on ? null : (requested ?? null)
|
||||
const toggle = offered ? (
|
||||
<label className="flex cursor-pointer items-center gap-2 text-xs text-muted">
|
||||
<input type="checkbox" checked={on} onChange={(e) => setOn(e.target.checked)} className="accent-accent" />
|
||||
Also add to “{requested.name}”
|
||||
</label>
|
||||
) : null
|
||||
return { target, toggle }
|
||||
}
|
||||
|
||||
/** Where tracks headed for the collection come from: another library's or a
|
||||
@@ -74,8 +96,9 @@ function removableWarning(p: FolderAddPreview, newCount: number): string {
|
||||
return `${what} on ${where}. They will go missing from your collection whenever ${unplugged} unplugged.`
|
||||
}
|
||||
|
||||
export function AddFilesDialog({ trackIds, target, note, onClose, onDone, onError }: Props) {
|
||||
export function AddFilesDialog({ trackIds, target: requested, note, onClose, onDone, onError }: Props) {
|
||||
const qc = useQueryClient()
|
||||
const { target, toggle } = usePlaylistToggle(requested)
|
||||
// The LIBRARY's capabilities (this dialog is mounted outside the browsed
|
||||
// view's swapped context). A library that places its own audio — a stick —
|
||||
// decides copy vs in place itself, so there is nothing to ask.
|
||||
@@ -115,6 +138,7 @@ export function AddFilesDialog({ trackIds, target, note, onClose, onDone, onErro
|
||||
mode: places ? 'copy' : (mode ?? 'reference'),
|
||||
destination: !places && mode === 'copy' ? folder : null,
|
||||
playlist_id: target?.kind === 'playlist' ? target.id : null,
|
||||
playlist_index: target?.kind === 'playlist' ? (target.index ?? null) : null,
|
||||
export_id: target?.kind === 'export' ? target.id : null,
|
||||
}
|
||||
|
||||
@@ -255,6 +279,7 @@ export function AddFilesDialog({ trackIds, target, note, onClose, onDone, onErro
|
||||
<div className="space-y-4 px-5 py-4 text-sm">
|
||||
{!job && (
|
||||
<>
|
||||
{toggle}
|
||||
{target && (
|
||||
<div className="text-xs text-muted">
|
||||
{target.kind === 'playlist' ? 'Playlists' : 'Exports'} hold tracks from your
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useCaps } from '../lib/capabilities'
|
||||
import { placedAudioSummary } from '../lib/platformCopy'
|
||||
import type { AddTarget } from './AddFilesDialog'
|
||||
import { FolderPicker } from './FolderPicker'
|
||||
import { useServerImportFolder } from './AddFilesDialog'
|
||||
import { useServerImportFolder, usePlaylistToggle } from './AddFilesDialog'
|
||||
|
||||
/**
|
||||
* Import a browsed device into the loaded collection.
|
||||
@@ -41,8 +41,9 @@ interface Props {
|
||||
onError: (msg: string) => void
|
||||
}
|
||||
|
||||
export function ImportDialog({ playlistId, trackIds, target, deviceLabel, onClose, onDone, onError }: Props) {
|
||||
export function ImportDialog({ playlistId, trackIds, target: requested, deviceLabel, onClose, onDone, onError }: Props) {
|
||||
const qc = useQueryClient()
|
||||
const { target, toggle } = usePlaylistToggle(requested)
|
||||
// The BASE folder, and whether to put this device's audio in its own
|
||||
// subfolder of it. Kept apart rather than as one path because they are two
|
||||
// different decisions: where your music lives, and how one import is filed
|
||||
@@ -91,6 +92,7 @@ export function ImportDialog({ playlistId, trackIds, target, deviceLabel, onClos
|
||||
track_ids: trackIds ?? [],
|
||||
folder_name: deviceLabel,
|
||||
into_playlist: target?.kind === 'playlist' ? target.id : null,
|
||||
into_playlist_index: target?.kind === 'playlist' ? (target.index ?? null) : null,
|
||||
export_id: target?.kind === 'export' ? target.id : null,
|
||||
}
|
||||
|
||||
@@ -203,6 +205,7 @@ export function ImportDialog({ playlistId, trackIds, target, deviceLabel, onClos
|
||||
<div className="space-y-4 px-5 py-4 text-sm">
|
||||
{!job && (
|
||||
<>
|
||||
{toggle}
|
||||
{places && p && (
|
||||
<div className="rounded well px-3 py-2 text-xs text-muted">
|
||||
{placedAudioSummary(caps.save, p.copied ?? 0, p.in_place ?? 0)}
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
} from '@dnd-kit/sortable'
|
||||
import { CSS } from '@dnd-kit/utilities'
|
||||
import type { Track, TrackOrigin } from '../api'
|
||||
import { beginDrag, useDragPayload, useDropTarget } from '../lib/drag'
|
||||
import { beginDrag, isForeign, useDragPayload, useDropTarget, type TracksOrFiles } from '../lib/drag'
|
||||
import { hasMod } from '../lib/modKey'
|
||||
import { TRACK_COLUMNS } from '../lib/trackColumns'
|
||||
|
||||
@@ -76,6 +76,11 @@ interface Props {
|
||||
/** Where dragged rows come from: whose ids they are, and the editable
|
||||
* playlist they leave on a Cmd/Ctrl-drag (move). Defaults to the collection. */
|
||||
dragFrom?: { origin: TrackOrigin; playlistId?: string }
|
||||
/** Things from outside the library dropped on the table — files from the
|
||||
* OS, a Files folder's or a device's rows — headed for this view's
|
||||
* playlist. `index` is the insertion line while `reorder` is enabled (the
|
||||
* rows ARE the entry list then), else null: appended. */
|
||||
foreignDrop?: { label: string; onDrop: (p: TracksOrFiles, index: number | null) => void }
|
||||
/** Delete/Backspace removes the selected tracks from this view. */
|
||||
onRemove?: (ids: string[]) => void
|
||||
/** `viewIds` is every row's id in the order shown (sorted, filtered). */
|
||||
@@ -285,6 +290,7 @@ export function TrackTable({
|
||||
positions,
|
||||
marked,
|
||||
reorder,
|
||||
foreignDrop,
|
||||
dragFrom,
|
||||
onRemove,
|
||||
onRowContextMenu,
|
||||
@@ -447,14 +453,25 @@ export function TrackTable({
|
||||
}
|
||||
}, [tableKey])
|
||||
|
||||
const [dropRef, dropHint] = useDropTarget<{ drop: number }>({
|
||||
// The table's own rows (reorder) and, where `foreignDrop` is given,
|
||||
// things from outside the library (see the prop).
|
||||
const foreignDropRef = useRef(foreignDrop)
|
||||
foreignDropRef.current = foreignDrop
|
||||
const [dropRef, dropHint] = useDropTarget<{ drop: number | null }>({
|
||||
hint: (p, at) => {
|
||||
if (p.kind !== 'tracks' || p.source !== tableKey || !reorderRef.current?.enabled) return null
|
||||
const own = p.kind === 'tracks' && p.source === tableKey
|
||||
if (!own && !(foreignDropRef.current && isForeign(p))) return null
|
||||
if (!reorderRef.current?.enabled) return own ? null : { drop: null }
|
||||
const top = bodyRef.current?.getBoundingClientRect().top ?? 0
|
||||
return { drop: Math.max(0, Math.min(rowsRef.current.length, Math.round((at.y - top) / ROW_HEIGHT))) }
|
||||
},
|
||||
label: (p) => (p.kind === 'tracks' && p.source === tableKey ? null : (foreignDropRef.current?.label ?? null)),
|
||||
onDrop: (p, { drop }) => {
|
||||
if (p.kind !== 'tracks') return
|
||||
if (p.kind !== 'tracks' || p.source !== tableKey) {
|
||||
if (isForeign(p)) foreignDropRef.current?.onDrop(p, drop)
|
||||
return
|
||||
}
|
||||
if (drop === null) return
|
||||
const ids = new Set(p.ids)
|
||||
const rs = rowsRef.current.map((r) => r.original)
|
||||
const kept = rs.filter((t) => !ids.has(t.id))
|
||||
@@ -547,7 +564,9 @@ export function TrackTable({
|
||||
<div
|
||||
ref={scrollerRef}
|
||||
data-drag-scroll={bodyOffset.header}
|
||||
className="h-full overflow-auto px-1.5"
|
||||
className={`h-full overflow-auto px-1.5 ${
|
||||
dropHint && dropHint.drop === null ? 'rounded-lg outline-2 -outline-offset-2 outline-accent' : ''
|
||||
}`}
|
||||
onClick={(e) => {
|
||||
// A click in the empty space below the rows clears the selection.
|
||||
const t = e.target as HTMLElement
|
||||
@@ -621,7 +640,7 @@ export function TrackTable({
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{dropHint && (
|
||||
{dropHint && dropHint.drop !== null && (
|
||||
<div
|
||||
className="pointer-events-none absolute left-0 z-10 h-0.5 w-full bg-accent"
|
||||
style={{ top: dropHint.drop * ROW_HEIGHT - 1 }}
|
||||
|
||||
Reference in new issue
Block a user