Skip to content

The open alternative to Salesforce, designed for AI.

Favorite: computeNewPosition fixed (#2134)

Abhishek Thory159d2978d09d
diff --git a/front/src/modules/favorites/hooks/useFavorites.ts b/front/src/modules/favorites/hooks/useFavorites.ts
index 3dc348260b7..42fa2369bb0 100644
--- a/front/src/modules/favorites/hooks/useFavorites.ts
+++ b/front/src/modules/favorites/hooks/useFavorites.ts
@@ -104,7 +104,7 @@ export const useFavorites = () => {
});
};
- const computeNewPosition = (destIndex: number) => {
+ const computeNewPosition = (destIndex: number, sourceIndex: number) => {
if (destIndex === 0) {
return favorites[destIndex].position / 2;
}
@@ -112,6 +112,13 @@ export const useFavorites = () => {
if (destIndex === favorites.length - 1) {
return favorites[destIndex].position + 1;
}
+
+ if (sourceIndex < destIndex) {
+ return (
+ (favorites[destIndex + 1].position + favorites[destIndex].position) / 2
+ );
+ }
+
return (
(favorites[destIndex - 1].position + favorites[destIndex].position) / 2
);
@@ -121,7 +128,10 @@ export const useFavorites = () => {
if (!result.destination || !favorites) {
return;
}
- const newPosition = computeNewPosition(result.destination.index);
+ const newPosition = computeNewPosition(
+ result.destination.index,
+ result.source.index,
+ );
const reorderFavorites = Array.from(favorites);
const [removed] = reorderFavorites.splice(result.source.index, 1);