From da4284bac0f1b1585eae917c5384802a6b43a3a9 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Mon, 18 May 2026 18:13:05 -0700 Subject: [PATCH] fix playlist folder drop on root behavior - previously, nested folders dropped onto root would destroy the folder. instead, move the nested folder into the root --- .../components/playlist-folder-tree.tsx | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/renderer/features/sidebar/components/playlist-folder-tree.tsx b/src/renderer/features/sidebar/components/playlist-folder-tree.tsx index 35b815f0a..0487af289 100644 --- a/src/renderer/features/sidebar/components/playlist-folder-tree.tsx +++ b/src/renderer/features/sidebar/components/playlist-folder-tree.tsx @@ -123,6 +123,32 @@ export const remapPlaylistToRoot = (playlistName: string, separator: string): st return getPlaylistLeafName(playlistName, separator).trim(); }; +export const isRootLevelFolder = (folderPath: string, separator: string): boolean => { + const segments = folderPath.split(separator).filter((segment) => segment.length > 0); + return segments.length === 1; +}; + +export const remapPlaylistFolderToRoot = ( + playlistName: string, + sourceFolderPath: string, + separator: string, +): null | string => { + const sourcePrefix = `${sourceFolderPath}${separator}`; + if (!playlistName.startsWith(sourcePrefix)) return null; + + const remainder = playlistName.slice(sourcePrefix.length); + if (!remainder) return null; + + // Root-level folder on root: flatten playlists to root (Rock/x -> x). + if (isRootLevelFolder(sourceFolderPath, separator)) { + return remapPlaylistToRoot(playlistName, separator); + } + + // Nested folder on root: promote one level (Auto/Test/x -> Test/x). + const folderName = getFolderName(sourceFolderPath, separator); + return `${folderName}${separator}${remainder}`; +}; + const updatePlaylistName = async ( updateMutation: ReturnType, serverId: string, @@ -169,12 +195,14 @@ export const usePlaylistRootDrop = (allPlaylists: Playlist[]) => { ); for (const playlist of affected) { - await updatePlaylistName( - updateMutation, - serverId, - playlist, - remapPlaylistToRoot(playlist.name, separator), + const newName = remapPlaylistFolderToRoot( + playlist.name, + sourceFolderPath, + separator, ); + if (!newName) continue; + + await updatePlaylistName(updateMutation, serverId, playlist, newName); } return;