fix(playlists): remove-from-playlist operates on full tree and also removes ids from custom order; reload structure after save

This commit is contained in:
Geert Rademakes 2025-08-08 16:50:13 +02:00
parent 924f36f4f7
commit a7ccadc8ac

View File

@ -298,31 +298,29 @@ const RekordboxReader: React.FC = () => {
const handleRemoveFromPlaylist = async (songIds: string[]) => { const handleRemoveFromPlaylist = async (songIds: string[]) => {
if (currentPlaylist === "All Songs") return; if (currentPlaylist === "All Songs") return;
const updatedPlaylists = playlists.map(node => { // Operate on FULL playlist tree to avoid losing data
if (node.name === currentPlaylist && node.type === 'playlist') { const fullTree = await api.getPlaylists();
return {
...node, const applyRemove = (nodes: PlaylistNode[]): PlaylistNode[] => {
tracks: (node.tracks || []).filter(id => !songIds.includes(id)) 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) { if (node.type === 'folder' && node.children) {
return { return { ...node, children: applyRemove(node.children) } as PlaylistNode;
...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; return node;
}); });
const savedPlaylists = await api.savePlaylists(updatedPlaylists); };
setPlaylists(savedPlaylists);
const updatedFullTree = applyRemove(fullTree);
await api.savePlaylists(updatedFullTree);
// Reload structure for UI state
const structure = await api.getPlaylistStructure();
setPlaylists(structure);
}; };