feat: add profile reordering

This commit is contained in:
Xyphyn committed 2023-08-19 17:48:55 -07:00
1 parent 8182fa09e7
commit 5ae9894ec5
4 files changed
+55 -8

No files matched your search

+25
View File
@@ -56,3 +56,28 @@ export const placeholders = {
: ''
},
}
export function moveItem<T>(
array: T[],
currentIndex: number,
newIndex: number
): T[] {
if (
currentIndex < 0 ||
currentIndex >= array.length ||
newIndex < 0 ||
newIndex >= array.length
) {
throw new Error('Invalid index')
}
const newArray = [...array]
// Remove the item from the current index
const [item] = newArray.splice(currentIndex, 1)
// Insert the item at the new index
newArray.splice(newIndex, 0, item)
return newArray
}