refactor: css variables for colors and shadows
This commit is contained in:
@ -62,40 +62,39 @@ const SortableDnd = <T extends BaseItem>({
|
||||
const sensors = useDndSensors();
|
||||
|
||||
const onDragEndLocal = ({ active, over }: DragEndEvent) => {
|
||||
if (over && active.id !== over?.id && activeItem) {
|
||||
const overIndex: number = items.findIndex(
|
||||
({ id }) => id === over.id
|
||||
);
|
||||
const activeIndex: number = items.findIndex(
|
||||
({ id }) => id === activeItem.id
|
||||
);
|
||||
|
||||
let leftIndex = overIndex;
|
||||
let rightIndex = overIndex + 1;
|
||||
if (overIndex < activeIndex) {
|
||||
leftIndex = overIndex - 1;
|
||||
rightIndex = overIndex;
|
||||
}
|
||||
|
||||
const leftLexorank: LexoRank | null =
|
||||
leftIndex >= 0
|
||||
? LexoRank.parse(items[leftIndex].lexorank)
|
||||
: null;
|
||||
const rightLexorank: LexoRank | null =
|
||||
rightIndex < items.length
|
||||
? LexoRank.parse(items[rightIndex].lexorank)
|
||||
: null;
|
||||
|
||||
const newLexorank = getNewLexorank(
|
||||
leftLexorank,
|
||||
rightLexorank
|
||||
).toString();
|
||||
|
||||
items[activeIndex].lexorank = newLexorank;
|
||||
onDragEnd(items[activeIndex].id, newLexorank);
|
||||
const sortedItems = sortByLexorank(items);
|
||||
setItems([...sortedItems]);
|
||||
if (!over || active.id === over?.id || !activeItem) {
|
||||
setActive(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const overIndex: number = items.findIndex(({ id }) => id === over.id);
|
||||
const activeIndex: number = items.findIndex(
|
||||
({ id }) => id === activeItem.id
|
||||
);
|
||||
|
||||
let leftIndex = overIndex;
|
||||
let rightIndex = overIndex + 1;
|
||||
if (overIndex < activeIndex) {
|
||||
leftIndex = overIndex - 1;
|
||||
rightIndex = overIndex;
|
||||
}
|
||||
|
||||
const leftLexorank: LexoRank | null =
|
||||
leftIndex >= 0 ? LexoRank.parse(items[leftIndex].lexorank) : null;
|
||||
const rightLexorank: LexoRank | null =
|
||||
rightIndex < items.length
|
||||
? LexoRank.parse(items[rightIndex].lexorank)
|
||||
: null;
|
||||
|
||||
const newLexorank = getNewLexorank(
|
||||
leftLexorank,
|
||||
rightLexorank
|
||||
).toString();
|
||||
|
||||
items[activeIndex].lexorank = newLexorank;
|
||||
onDragEnd(items[activeIndex].id, newLexorank);
|
||||
const sortedItems = sortByLexorank(items);
|
||||
setItems([...sortedItems]);
|
||||
setActive(null);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user