fix(dnd): pass onDropSongs into top-level PlaylistItem instances as well (not only nested)

This commit is contained in:
Geert Rademakes 2025-08-08 13:48:23 +02:00
parent dc11487a9f
commit e622219e12
2 changed files with 19 additions and 2 deletions

View File

@ -261,6 +261,7 @@ const RekordboxReader: React.FC = () => {
// Handle drop from song list into playlist (with duplicate check and user choice)
const handleDropSongsToPlaylist = async (playlistName: string, songIds: string[]) => {
console.debug('[DnD] App received drop', { playlistName, count: songIds?.length, songIds });
// Find target playlist current tracks
const findNode = (nodes: PlaylistNode[]): PlaylistNode | null => {
for (const n of nodes) {
@ -273,7 +274,10 @@ const RekordboxReader: React.FC = () => {
return null;
};
const target = findNode(playlists);
if (!target) return;
if (!target) {
console.debug('[DnD] target playlist not found', playlistName);
return;
}
const existing = new Set(target?.tracks || []);
const dupes = songIds.filter(id => existing.has(id));
@ -285,8 +289,12 @@ const RekordboxReader: React.FC = () => {
}
const finalIds = proceedMode === 'skip' ? songIds.filter(id => !existing.has(id)) : songIds;
if (finalIds.length === 0) return;
if (finalIds.length === 0) {
console.debug('[DnD] nothing to add after duplicate filter');
return;
}
await handleAddSongsToPlaylist(finalIds, playlistName);
console.debug('[DnD] add completed');
toast({
title: 'Songs Added',
description: `${finalIds.length} song${finalIds.length === 1 ? '' : 's'} added to "${playlistName}"`,

View File

@ -255,9 +255,17 @@ const PlaylistItem: React.FC<PlaylistItemProps> = React.memo(({
} else if ((window as any).__rbDragPayload) {
parsed = (window as any).__rbDragPayload;
}
console.debug('[DnD] drop playlist handler presence', node.name, Boolean(onDropSongs));
if (parsed?.type === 'songs' && Array.isArray(parsed.songIds) && onDropSongs) {
console.debug('[DnD] invoking onDropSongs', node.name, parsed.songIds.length);
onDropSongs(node.name, parsed.songIds);
} else {
console.debug('[DnD] drop playlist no action', node.name, {
hasParsed: Boolean(parsed),
type: parsed?.type,
isArray: Array.isArray(parsed?.songIds),
hasHandler: Boolean(onDropSongs)
});
}
console.debug('[DnD] drop playlist', node.name, parsed, 'raw len', json?.length || 0);
} catch (err) {
@ -448,6 +456,7 @@ export const PlaylistManager: React.FC<PlaylistManagerProps> = ({
onPlaylistDelete={onPlaylistDelete}
onPlaylistMove={onPlaylistMove}
allFolders={allFolders}
onDropSongs={onDropSongs}
/>
))}
</VStack>