Skip to content

Commit

Permalink
fix: 修复计算问题
Browse files Browse the repository at this point in the history
  • Loading branch information
limaofeng committed Nov 13, 2021
1 parent d3c32b9 commit 6f3499c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/SortableProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,9 @@ function useStore(items: ISortableItem[], pos: number[]): ISortableContext {
(dispatch as any)({
type: SortableActionType.init,
payload: {
items: outside.map((item, index) => {
items: outside.map((item) => {
const data = state.items.find((x) => x.id == item.id);
if (!data) {
item.index = index;
item.pos = state.pos ? [...state.pos, index] : item.pos;
return item;
}
const { _originalSortable, _sortable, _rect, ...prevData } = data;
Expand All @@ -379,6 +377,9 @@ function useStore(items: ISortableItem[], pos: number[]): ISortableContext {
id: state.id,
},
});
if (!!state.pos) {
(dispatch as any)({ type: SortableActionType.UPDATE_POS, payload: state.pos });
}
}, [outside]);

useEffect(() => {
Expand Down
5 changes: 0 additions & 5 deletions src/hooks/useSortItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,6 @@ function useSortItem<T extends ISortableItem, RT extends HTMLElement>(
});
}, [sortableId]);

// useEffect(() => {
// // console.log('handleUpdate pos', pos, options?.index);
// handleUpdate({ ...dataRef.current, index: options?.index, pos: [...pos, options?.index] });
// }, [options?.index, pos.join('-')]);

return [
{
clicked: clicked.current,
Expand Down

0 comments on commit 6f3499c

Please sign in to comment.