fix(dnd): bubble drop handler through nested folders; add debug log on handler invoke; harden /playlists/batch insertMany

This commit is contained in:
Geert Rademakes 2025-08-08 13:39:39 +02:00
parent 6eabfdedd0
commit dc11487a9f
3 changed files with 8 additions and 2 deletions

View File

@ -69,8 +69,10 @@ router.get('/structure', async (req: Request, res: Response) => {
// Save playlists in batch (replacing all existing ones)
router.post('/batch', async (req, res) => {
try {
await Playlist.deleteMany({}); // Clear existing playlists
const playlists = await Playlist.create(req.body);
// Replace all playlists atomically
await Playlist.deleteMany({});
const payload = Array.isArray(req.body) ? req.body : [];
const playlists = await Playlist.insertMany(payload, { ordered: false });
res.json(playlists);
} catch (error) {
console.error('Error saving playlists:', error);

View File

@ -250,7 +250,9 @@ const RekordboxReader: React.FC = () => {
};
const updatedFullTree = applyAdd(fullTree);
console.debug('[DnD] saving playlists with added tracks', { playlistName, addCount: songIds.length });
await api.savePlaylists(updatedFullTree);
console.debug('[DnD] playlists saved');
// Reload structure for UI counters
const structure = await api.getPlaylistStructure();

View File

@ -208,6 +208,7 @@ const PlaylistItem: React.FC<PlaylistItemProps> = React.memo(({
onPlaylistDelete={onPlaylistDelete}
onPlaylistMove={onPlaylistMove}
allFolders={allFolders}
onDropSongs={onDropSongs}
/>
))}
</VStack>
@ -255,6 +256,7 @@ const PlaylistItem: React.FC<PlaylistItemProps> = React.memo(({
parsed = (window as any).__rbDragPayload;
}
if (parsed?.type === 'songs' && Array.isArray(parsed.songIds) && onDropSongs) {
console.debug('[DnD] invoking onDropSongs', node.name, parsed.songIds.length);
onDropSongs(node.name, parsed.songIds);
}
console.debug('[DnD] drop playlist', node.name, parsed, 'raw len', json?.length || 0);