From a7ccadc8ac4db29a2a9eb2bb22962bc6b17ed90b Mon Sep 17 00:00:00 2001 From: Geert Rademakes Date: Fri, 8 Aug 2025 16:50:13 +0200 Subject: [PATCH] fix(playlists): remove-from-playlist operates on full tree and also removes ids from custom order; reload structure after save --- packages/frontend/src/App.tsx | 48 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/packages/frontend/src/App.tsx b/packages/frontend/src/App.tsx index fd6cffa..62e07c5 100644 --- a/packages/frontend/src/App.tsx +++ b/packages/frontend/src/App.tsx @@ -298,31 +298,29 @@ const RekordboxReader: React.FC = () => { const handleRemoveFromPlaylist = async (songIds: string[]) => { if (currentPlaylist === "All Songs") return; - const updatedPlaylists = playlists.map(node => { - if (node.name === currentPlaylist && node.type === 'playlist') { - return { - ...node, - tracks: (node.tracks || []).filter(id => !songIds.includes(id)) - }; - } - if (node.type === 'folder' && node.children) { - return { - ...node, - children: node.children.map(child => { - if (child.name === currentPlaylist && child.type === 'playlist') { - return { - ...child, - tracks: (child.tracks || []).filter(id => !songIds.includes(id)) - }; - } - return child; - }) - }; - } - return node; - }); - const savedPlaylists = await api.savePlaylists(updatedPlaylists); - setPlaylists(savedPlaylists); + // Operate on FULL playlist tree to avoid losing data + const fullTree = await api.getPlaylists(); + + const applyRemove = (nodes: PlaylistNode[]): PlaylistNode[] => { + return nodes.map(node => { + if (node.type === 'playlist' && node.name === currentPlaylist) { + const remainingTracks = (node.tracks || []).filter(id => !songIds.includes(id)); + const remainingOrder = (node.order || []).filter(id => !songIds.includes(id)); + return { ...node, tracks: remainingTracks, order: remainingOrder } as PlaylistNode; + } + if (node.type === 'folder' && node.children) { + return { ...node, children: applyRemove(node.children) } as PlaylistNode; + } + return node; + }); + }; + + const updatedFullTree = applyRemove(fullTree); + await api.savePlaylists(updatedFullTree); + + // Reload structure for UI state + const structure = await api.getPlaylistStructure(); + setPlaylists(structure); };