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:
parent
924f36f4f7
commit
a7ccadc8ac
@ -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))
|
||||
};
|
||||
// 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: 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, children: applyRemove(node.children) } as PlaylistNode;
|
||||
}
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user