diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dc00746..6196e44b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. - Change bootstrap column class from `col-md-8` -> `col-md-12` - update api.generated.ts to match [related pr](https://github.com/os2display/display-api-service/pull/213) - Add @rtk-incubator/rtk-query-codegen-openapi to package.json in `src/redux/api` + - Sort playlists based on weight in drag/drop component ## [2.1.0] - 2024-10-23 diff --git a/src/components/playlist-drag-and-drop/playlist-drag-and-drop.jsx b/src/components/playlist-drag-and-drop/playlist-drag-and-drop.jsx index 706b074a..755a50c6 100644 --- a/src/components/playlist-drag-and-drop/playlist-drag-and-drop.jsx +++ b/src/components/playlist-drag-and-drop/playlist-drag-and-drop.jsx @@ -77,12 +77,14 @@ function PlaylistDragAndDrop({ if (selectedPlaylistsByRegion) { setTotalItems(selectedPlaylistsByRegion["hydra:totalItems"]); const newPlaylists = selectedPlaylistsByRegion["hydra:member"].map( - ({ playlist }) => { - return playlist; - } + ({ playlist, weight }) => ({ ...playlist, weight }) ); - setSelectedData([...selectedData, ...newPlaylists]); + const selected = [...selectedData, ...newPlaylists].sort( + (a, b) => a.weight - b.weight + ); + + setSelectedData(selected); callbackToinitializePlaylists(selectedPlaylistsByRegion); } }, [selectedPlaylistsByRegion]);