Sorting playlist tracks, fixes #568

This commit is contained in:
James Barnsley
2020-11-07 16:46:09 +13:00
parent 1395ed7662
commit fdd3bf3bc9
16 changed files with 681 additions and 367 deletions

View File

@ -929,6 +929,17 @@ const collate = function (obj, indexes = {}) {
return obj;
};
/**
* Add the array index as our sort_id.
* This allows us a source of truth for the original order of items when we have applied
* sort rules in the UI.
*
* @param {Array} array of objects to have sort_id added
*/
const injectSortId = (array) => {
return array.map((item, index) => ({ ...item, sort_id: index }));
};
export {
toJSON,
getTrackIcon,
@ -952,6 +963,7 @@ export {
formatCategories,
collate,
collateLibrary,
injectSortId,
};
export default {
@ -977,4 +989,5 @@ export default {
formatCategories,
collate,
collateLibrary,
injectSortId,
};