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
This commit is contained in:
jeffvli
2026-05-18 18:13:05 -07:00
parent f3c0b68a0f
commit da4284bac0
@@ -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<typeof useUpdatePlaylist>,
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;