This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
2021-07-28 19:56:29 +00:00
|
|
|
export const calculateItemPosition = (positionBefore: number | null, positionAfter: number | null): number => {
|
2022-10-04 10:48:23 +00:00
|
|
|
if (positionBefore === null) {
|
|
|
|
if (positionAfter === null) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no task after it, we just add 2^16 to the last position to have enough room in the future
|
2021-07-28 19:56:29 +00:00
|
|
|
return positionAfter / 2
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no task after it, we just add 2^16 to the last position to have enough room in the future
|
2022-10-04 10:48:23 +00:00
|
|
|
if (positionAfter === null) {
|
2021-07-28 19:56:29 +00:00
|
|
|
return positionBefore + Math.pow(2, 16)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have both a task before and after it, we acually calculate the position
|
|
|
|
return positionBefore + (positionAfter - positionBefore) / 2
|
|
|
|
}
|