Skip to content

Commit 422674e

Browse files
author
Alex Kühne
committed
Pass the correct card ID
1 parent 81d382a commit 422674e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

examples/04 Sortable/Simple/Card.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const style = {
1212

1313
const cardSource = {
1414
beginDrag(props) {
15-
return { id: props.id };
15+
return {
16+
id: props.id,
17+
index: props.index
18+
};
1619
}
1720
};
1821

@@ -23,10 +26,9 @@ const cardTarget = {
2326
if (draggedId === ownId) {
2427
return;
2528
}
26-
27-
// assuming something like findTodoIndex is implemented
28-
const ownIndex = props.findTodoIndex(ownId);
29-
const draggedIndex = props.findTodoIndex(draggedId);
29+
30+
const ownIndex = props.index;
31+
const draggedIndex = monitor.getItem().index;
3032

3133
// What is my rectangle on screen?
3234
const boundingRect = React.findDOMNode(component).getBoundingClientRect();

examples/04 Sortable/Simple/Container.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ export default class Container extends Component {
6262

6363
return (
6464
<div style={style}>
65-
{cards.map(card => {
65+
{cards.map((card, i) => {
6666
return (
6767
<Card key={card.id}
68+
index={i}
6869
id={card.id}
6970
text={card.text}
7071
moveCard={this.moveCard} />

0 commit comments

Comments
 (0)