feat: rest revamp (#2918)

Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
Co-authored-by: Nivedin <53208152+nivedin@users.noreply.github.com>
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
Anwarul Islam
2023-03-31 01:15:42 +06:00
committed by GitHub
parent dbb45e7253
commit defece95fc
63 changed files with 2262 additions and 1924 deletions

View File

@@ -0,0 +1,21 @@
/**
* Get the indexes that are affected by the reorder
* @param from index of the item before reorder
* @param to index of the item after reorder
* @returns Map of from to to
*/
export function getAffectedIndexes(from: number, to: number) {
const indexes = new Map<number, number>()
indexes.set(from, to)
if (from < to) {
for (let i = from + 1; i <= to; i++) {
indexes.set(i, i - 1)
}
} else {
for (let i = from - 1; i >= to; i--) {
indexes.set(i, i + 1)
}
}
return indexes
}