Skip to content

Commit

Permalink
Merge pull request #226 from IAmJulianAcosta/master
Browse files Browse the repository at this point in the history
  • Loading branch information
andresin87 authored Jan 30, 2022
2 parents 32365f4 + 362cbd5 commit fa17468
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions src/react-sortable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ export class ReactSortable<T extends ItemInterface> extends Component<
this.ref = createRef<HTMLElement>();

// make all state false because we can't change sortable unless a mouse gesture is made.
const newList = props.list.map((item) => ({
...item,
chosen: false,
selected: false,
}));
const newList = [...props.list];

newList.forEach((item: T) => {
Object.assign(item, {
chosen: false,
selected: false,
});
})

props.setList(newList, this.sortable, store);
invariant(
Expand Down Expand Up @@ -235,10 +238,14 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
const otherList = [...store.dragging!.props.list];
const customs = createCustoms(evt, otherList);
removeNodes(customs);
const newList = handleStateAdd(customs, list, evt, clone).map((item) => ({
...item,
selected: false,
}));

const newList = handleStateAdd(customs, list, evt, clone)

newList.forEach((item) => {
Object.assign(item, {
selected: false,
});
});
setList(newList, this.sortable, store);
}

Expand Down Expand Up @@ -289,7 +296,11 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
}

// remove item.selected from list
newList = newList.map((item) => ({ ...item, selected: false }));
newList.forEach((item: T) => {
Object.assign(item, {
selected: false,
});
})
setList(newList, this.sortable, store);
}

Expand All @@ -314,10 +325,9 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
const { list, setList } = this.props;
const newList = list.map((item, index) => {
if (index === evt.oldIndex) {
return {
...item,
Object.assign(item, {
chosen: true,
};
});
}
return item;
});
Expand All @@ -328,10 +338,9 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl
const { list, setList } = this.props;
const newList = list.map((item, index) => {
if (index === evt.oldIndex) {
return {
...item,
Object.assign(item, {
chosen: false,
};
});
}
return item;
});
Expand All @@ -345,7 +354,12 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl

onSelect(evt: MultiDragEvent): void {
const { list, setList } = this.props;
const newList = list.map((item) => ({ ...item, selected: false }));
const newList = [...list];
newList.forEach((item) => {
Object.assign(item, {
chosen: false,
});
});
evt.newIndicies.forEach((curr) => {
const index = curr.index;
if (index === -1) {
Expand All @@ -362,7 +376,12 @@ Please read the updated README.md at https://github.com/SortableJS/react-sortabl

onDeselect(evt: MultiDragEvent): void {
const { list, setList } = this.props;
const newList = list.map((item) => ({ ...item, selected: false }));
const newList = [...list];
newList.forEach((item) => {
Object.assign(item, {
chosen: false,
});
});
evt.newIndicies.forEach((curr) => {
const index = curr.index;
if (index === -1) return;
Expand Down

0 comments on commit fa17468

Please sign in to comment.