mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Implemented drag to import
This commit is contained in:
1 parent
87cbd3720e
commit
a65ef959b2
14 files changed
+807
-114
No files matched your search
@@ -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, isServerPath, type FolderAddPreview, type FolderAddRequest, type JobStatus } from '../api'
|
||||
import { api, isServerPath, type FolderAddPreview, type FolderAddRequest, type JobStatus, type TrackOrigin } from '../api'
|
||||
import { useCaps } from '../lib/capabilities'
|
||||
import { placedAudioSummary } from '../lib/platformCopy'
|
||||
import { FolderPicker } from './FolderPicker'
|
||||
@@ -25,6 +25,10 @@ import { FolderPicker } from './FolderPicker'
|
||||
* library can reach them, so they are added in place, uploaded nowhere and
|
||||
* nothing asked (decided 2026-10-10).
|
||||
*
|
||||
* Files dropped onto the window from the OS (`lib/fileDrop.ts`) arrive here
|
||||
* too, so a drop asks exactly what the sidebar's Add to Collection asks. A
|
||||
* drop can mix drives, so the external-drive warning counts files per 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
|
||||
@@ -45,15 +49,32 @@ export interface AddTarget {
|
||||
name: string
|
||||
}
|
||||
|
||||
/** Where tracks headed for the collection come from: another library's or a
|
||||
* folder's track ids, or — `dropped` — paths dragged in from the OS. */
|
||||
export type ForeignOrigin = TrackOrigin | 'dropped'
|
||||
|
||||
interface Props {
|
||||
trackIds: string[]
|
||||
target: AddTarget | null
|
||||
/** A line about what was left out before the dialog (a drop's non-audio files). */
|
||||
note?: string | null
|
||||
onClose: () => void
|
||||
onDone: (msg: string) => void
|
||||
onError: (msg: string) => void
|
||||
}
|
||||
|
||||
export function AddFilesDialog({ trackIds, target, onClose, onDone, onError }: Props) {
|
||||
/** The leave-in-place warning, per drive: a drop can mix the computer's own
|
||||
* disk with a stick, and only the stick's files go missing on unplug. */
|
||||
function removableWarning(p: FolderAddPreview, newCount: number): string {
|
||||
const count = p.removable_count ?? newCount
|
||||
const drives = p.removable_drives ?? []
|
||||
const where = drives.length === 1 ? `${drives[0]}, an external drive` : 'external drives'
|
||||
const what = count >= newCount ? 'These files are' : `${count} of these files are`
|
||||
const unplugged = drives.length === 1 ? 'it is' : 'they are'
|
||||
return `${what} on ${where}. They will go missing from your collection whenever ${unplugged} unplugged.`
|
||||
}
|
||||
|
||||
export function AddFilesDialog({ trackIds, target, note, onClose, onDone, onError }: Props) {
|
||||
const qc = useQueryClient()
|
||||
// The LIBRARY's capabilities (this dialog is mounted outside the browsed
|
||||
// view's swapped context). A library that places its own audio — a stick —
|
||||
@@ -177,9 +198,12 @@ export function AddFilesDialog({ trackIds, target, onClose, onDone, onError }: P
|
||||
const newCount = p?.importable ?? 0
|
||||
const shown = places ? 'placed' : mode
|
||||
const libraryName = places ? caps.save.app_name : 'your collection'
|
||||
// Every file is held already: nothing is copied or referenced, so there is
|
||||
// nothing to ask — only the target to fill.
|
||||
const nothingNew = !!p && newCount === 0 && p.existing.length > 0
|
||||
const canAdd =
|
||||
!starting && shown !== null && !!p && (newCount > 0 || (!!target && p.existing.length > 0)) &&
|
||||
p.enough_space !== false
|
||||
!starting && (shown !== null || nothingNew) && !!p &&
|
||||
(newCount > 0 || (!!target && p.existing.length > 0)) && p.enough_space !== false
|
||||
|
||||
const title = target
|
||||
? `Add ${n} track${n === 1 ? '' : 's'} to ${target.name}`
|
||||
@@ -265,7 +289,9 @@ export function AddFilesDialog({ trackIds, target, onClose, onDone, onError }: P
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!places && !uploads && !onServer && (
|
||||
{note && <div className="text-xs text-muted">{note}</div>}
|
||||
|
||||
{!places && !uploads && !onServer && !nothingNew && (
|
||||
<div className="space-y-1">
|
||||
{option(
|
||||
'copy',
|
||||
@@ -296,9 +322,14 @@ export function AddFilesDialog({ trackIds, target, onClose, onDone, onError }: P
|
||||
)}
|
||||
|
||||
{mode === 'reference' && p?.removable && (
|
||||
<div className="rounded well px-3 py-2 text-xs text-gold">{removableWarning(p, newCount)}</div>
|
||||
)}
|
||||
|
||||
{mode === 'copy' && !!p?.in_destination && (
|
||||
<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.
|
||||
{p.in_destination === newCount ? 'These files are' : `${p.in_destination} of these files are`}{' '}
|
||||
already in your import folder. Copying makes a second copy beside{' '}
|
||||
{p.in_destination === 1 ? 'it' : 'them'}.
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { api, type ExportSet, type TrackOrigin } from '../api'
|
||||
import type { AddTarget } from './AddFilesDialog'
|
||||
import { api, type ExportSet } from '../api'
|
||||
import type { AddTarget, ForeignOrigin } from './AddFilesDialog'
|
||||
import { useCaps } from '../lib/capabilities'
|
||||
import { ExportDialog } from './ExportDialog'
|
||||
import { ExportRunDialog } from './ExportRunDialog'
|
||||
@@ -31,7 +31,7 @@ interface Props {
|
||||
onSelect: (s: Source) => void
|
||||
onDone: (msg: string) => void
|
||||
onError: (msg: string) => void
|
||||
onAddForeign: (origin: TrackOrigin, ids: string[], target: AddTarget) => void
|
||||
onAddForeign: (origin: ForeignOrigin, ids: string[], target: AddTarget) => void
|
||||
}
|
||||
|
||||
export function ExportsSection({ source, onSelect, onDone, onError, onAddForeign }: Props) {
|
||||
@@ -151,7 +151,7 @@ function ExportRow({
|
||||
onDelete: () => void
|
||||
onDone: (msg: string) => void
|
||||
onError: (msg: string) => void
|
||||
onAddForeign: (origin: TrackOrigin, ids: string[], target: AddTarget) => void
|
||||
onAddForeign: (origin: ForeignOrigin, ids: string[], target: AddTarget) => void
|
||||
}) {
|
||||
const qc = useQueryClient()
|
||||
// The COLLECTION's capabilities (the sidebar sits outside the browsed view's
|
||||
@@ -196,14 +196,20 @@ function ExportRow({
|
||||
const accepts = (p: DragPayload) =>
|
||||
p.kind === 'tracks'
|
||||
? p.origin === 'collection' || (caps.writable && caps.tracks.addable)
|
||||
: playlistIdsUnder(p.node).length > 0
|
||||
: p.kind === 'files'
|
||||
? caps.writable && caps.tracks.addable
|
||||
: playlistIdsUnder(p.node).length > 0
|
||||
const [dropRef, over] = useDropTarget<true>({
|
||||
hint: (p) => (accepts(p) ? true : null),
|
||||
label: (p) =>
|
||||
p.kind === 'tracks' && p.origin === 'device'
|
||||
? `Import into export ${set.name}…`
|
||||
: `Add to export ${set.name}${p.kind === 'tracks' && p.origin === 'folder' ? '…' : ''}`,
|
||||
: `Add to export ${set.name}${(p.kind === 'tracks' && p.origin === 'folder') || p.kind === 'files' ? '…' : ''}`,
|
||||
onDrop: async (p) => {
|
||||
if (p.kind === 'files') {
|
||||
onAddForeign('dropped', p.paths, { kind: 'export', id: set.id, name: set.name })
|
||||
return
|
||||
}
|
||||
if (p.kind === 'tracks' && p.origin !== 'collection') {
|
||||
onAddForeign(p.origin, p.ids, { kind: 'export', id: set.id, name: set.name })
|
||||
return
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { api, type PlaylistKind, type PlaylistNode, type TrackOrigin } from '../api'
|
||||
import type { AddTarget } from './AddFilesDialog'
|
||||
import { api, type PlaylistKind, type PlaylistNode } from '../api'
|
||||
import type { AddTarget, ForeignOrigin } from './AddFilesDialog'
|
||||
import { useCaps } from '../lib/capabilities'
|
||||
import { SaveBar } from './SaveBar'
|
||||
import { confirmDiscardUnsaved } from '../lib/unsaved'
|
||||
@@ -14,7 +14,7 @@ import { ContextMenu, type MenuItem } from './ContextMenu'
|
||||
import { Icon, type IconName } from '../lib/icons'
|
||||
import { PlatformIcon } from '../lib/platformIcons'
|
||||
import { addTracksToPlaylist } from '../lib/addTracks'
|
||||
import { useDragPayload, usePressToDrag, useDropTarget, type DragPayload } from '../lib/drag'
|
||||
import { useDragPayload, usePressToDrag, useDropTarget, type DragPayload, type TracksOrFiles } from '../lib/drag'
|
||||
import { findNode, idsAfter, nodeIdsUnder, playlistIdsUnder } from '../lib/playlistTree'
|
||||
|
||||
/**
|
||||
@@ -55,9 +55,10 @@ interface Props {
|
||||
/** Open a drive's library as THE library (Devices' "Open for editing…"). */
|
||||
onOpenLibrary: (path: string) => void
|
||||
onDone: (msg: string) => void
|
||||
/** Tracks not in the collection yet (a device's, a folder's) dropped on a
|
||||
* playlist or export: open the dialog that adds them, target filled in. */
|
||||
onAddForeign: (origin: TrackOrigin, ids: string[], target: AddTarget) => void
|
||||
/** Tracks not in the collection yet (a device's, a folder's — or files
|
||||
* dropped from the OS, as paths) dropped on a playlist or export: open the
|
||||
* dialog that adds them, target filled in. */
|
||||
onAddForeign: (origin: ForeignOrigin, ids: string[], target: AddTarget) => void
|
||||
onOpenPathMapping: () => void
|
||||
/** After unsaved edits were discarded (SaveBar). */
|
||||
onDiscarded?: () => void
|
||||
@@ -111,11 +112,11 @@ interface RowActions {
|
||||
onPickExport: (e: React.MouseEvent<HTMLElement>, node: PlaylistNode) => void
|
||||
onCommitDraft: (name: string) => void
|
||||
onCancelDraft: () => void
|
||||
/** Whether a drag of tracks may drop on this playlist. */
|
||||
acceptsTracks: (node: PlaylistNode, p: Extract<DragPayload, { kind: 'tracks' }>) => boolean
|
||||
/** Whether a drag of tracks (or of files from the OS) may drop on this playlist. */
|
||||
acceptsTracks: (node: PlaylistNode, p: TracksOrFiles) => boolean
|
||||
/** Tracks dropped on a playlist; `alt` (Option) moves them out of the
|
||||
* playlist they came from. */
|
||||
onDropTracks: (node: PlaylistNode, p: Extract<DragPayload, { kind: 'tracks' }>, alt: boolean) => void
|
||||
onDropTracks: (node: PlaylistNode, p: TracksOrFiles, alt: boolean) => void
|
||||
/** Whether a node may be dragged elsewhere in the tree. */
|
||||
canMove: (node: PlaylistNode) => boolean
|
||||
/** A node dropped in the tree: `index` among `parentId`'s children,
|
||||
@@ -265,14 +266,14 @@ function NodeRow({
|
||||
label: (p, h, at) => {
|
||||
if (h.zone === 'tracks') {
|
||||
if (p.kind === 'tracks' && p.origin === 'device') return `Import into ${node.name}…`
|
||||
if (p.kind === 'tracks' && p.origin === 'folder') return `Add to ${node.name}…`
|
||||
if ((p.kind === 'tracks' && p.origin === 'folder') || p.kind === 'files') return `Add to ${node.name}…`
|
||||
return `${moves(p, at.alt) ? 'Move' : 'Add'} to ${node.name}`
|
||||
}
|
||||
if (h.zone === 'peek') return null
|
||||
return h.zone === 'into' || h.zone === 'first' ? `Move into ${node.name}` : `Move ${h.zone} ${node.name}`
|
||||
},
|
||||
onDrop: (p, h, at) => {
|
||||
if (p.kind === 'tracks') {
|
||||
if (p.kind !== 'node') {
|
||||
if (h.zone === 'tracks') actions.onDropTracks(node, p, at.alt)
|
||||
} else if ('parentId' in h) {
|
||||
actions.onMoveNode(p.node, h.parentId, h.index, h.zone === 'into' && !expanded ? node : null)
|
||||
@@ -664,7 +665,7 @@ export function Sidebar({
|
||||
acceptsTracks: (node, p) =>
|
||||
caps.writable &&
|
||||
node.can_add_tracks &&
|
||||
(p.origin === 'collection' ? p.fromPlaylist !== node.id : caps.tracks.addable),
|
||||
(p.kind === 'tracks' && p.origin === 'collection' ? p.fromPlaylist !== node.id : caps.tracks.addable),
|
||||
canMove: (node) => caps.writable && node.can_move,
|
||||
onMoveNode: async (node, parentId, index, into) => {
|
||||
try {
|
||||
@@ -678,6 +679,10 @@ export function Sidebar({
|
||||
}
|
||||
},
|
||||
onDropTracks: async (node, p, alt) => {
|
||||
if (p.kind === 'files') {
|
||||
onAddForeign('dropped', p.paths, { kind: 'playlist', id: node.id, name: node.name })
|
||||
return
|
||||
}
|
||||
if (p.origin !== 'collection') {
|
||||
onAddForeign(p.origin, p.ids, { kind: 'playlist', id: node.id, name: node.name })
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user