Fix position calculations -- favorites (#9202)

Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
nitin
2024-12-23 20:15:01 +05:30
committed by GitHub
parent 691fbbe576
commit 061c92069f
5 changed files with 30 additions and 20 deletions

View File

@ -10,18 +10,19 @@ export const calculateNewPosition = ({
items,
}: CalculateNewPositionParams): number => {
if (destinationIndex === 0) {
return items[0].position / 2;
return items[0].position - 1;
}
if (destinationIndex === items.length - 1) {
return items[destinationIndex - 1].position + 1;
if (destinationIndex === items.length) {
return items[items.length - 1].position + 1;
}
if (destinationIndex > sourceIndex) {
return (
(items[destinationIndex + 1].position +
items[destinationIndex].position +
(items[destinationIndex - 1].position -
items[destinationIndex].position) /
2
2
);
}