Skip to content

Commit 5ecf647

Browse files
committed
fix: Add MOVE_CARD to event bus. Fix the bug in appendCardsToLane helper when index is specified
1 parent f105beb commit 5ecf647

File tree

6 files changed

+24
-25
lines changed

6 files changed

+24
-25
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ eventBus.publish({type: 'ADD_CARD', laneId: 'COMPLETED', card: {id: "M1", title:
111111
//To remove a card
112112
eventBus.publish({type: 'REMOVE_CARD', laneId: 'PLANNED', cardId: "M1"})
113113

114-
<Board data={data}
115-
eventBusHandle={setEventBus}/>
114+
//To move a card from one lane to another
115+
eventBus.publish({type: 'MOVE_CARD', fromLaneId: 'PLANNED', toLaneId: 'WIP', cardId: 'Plan3', index: 0})
116+
117+
<Board data={data} eventBusHandle={setEventBus}/>
116118
```
117119

118120
The code will move the card `Buy Milk` from the planned lane to completed lane. We expect that this library can be wired to a backend push api that can alter the state of the board in realtime.

src/components/BoardContainer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class BoardContainer extends Component {
2424
case 'REFRESH_BOARD':
2525
return actions.loadBoard(event.data)
2626
case 'MOVE_CARD':
27-
return actions.moveCardAcrossLanes({fromLaneId: event.fromLaneId, toLaneId: event.toLaneID, cardId: event.cardId, index: event.index})
27+
return actions.moveCardAcrossLanes({fromLaneId: event.fromLaneId, toLaneId: event.toLaneId, cardId: event.cardId, index: event.index})
2828
}
2929
}
3030
}
@@ -98,7 +98,7 @@ class BoardContainer extends Component {
9898
const {id, droppable, ...otherProps} = lane
9999
return (
100100
<Lane
101-
key={`${id}`}
101+
key={id}
102102
id={id}
103103
index={index}
104104
droppable={droppable === undefined ? true : droppable}

src/components/Lane.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,6 @@ class Lane extends Component {
8383
}
8484
}
8585

86-
moveCardAcrossLanes = (fromLaneId, toLaneId, cardId) => {
87-
toLaneId &&
88-
this.props.actions.moveCardAcrossLanes({
89-
fromLaneId: fromLaneId,
90-
toLaneId: toLaneId,
91-
cardId: cardId
92-
})
93-
}
94-
9586
removeCard = (laneId, cardId) => {
9687
this.props.actions.removeCard({laneId: laneId, cardId: cardId})
9788
}
@@ -158,7 +149,6 @@ class Lane extends Component {
158149
tagStyle={tagStyle}
159150
cardStyle={cardStyle}
160151
moveCard={this.moveCard}
161-
moveCardAcrossLanes={this.moveCardAcrossLanes}
162152
removeCard={this.removeCard}
163153
onClick={e => this.handleCardClick(e, card)}
164154
onDelete={this.props.onCardDelete}

src/helpers/DragType.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/helpers/LaneHelper.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ const LaneHelper = {
2020
newCards = newCards.map(c => update(c, {laneId: {$set: laneId}}))
2121
return state.lanes.map(lane => {
2222
if (lane.id === laneId) {
23-
let cards = null
2423
if (index !== undefined) {
25-
cards = lane.cards
26-
cards.splice(index, 0, ...newCards)
24+
return update(lane, {cards: {$splice: [[index, 0, ...newCards]]}})
2725
} else {
28-
cards = [...lane.cards, ...newCards]
26+
const cardsToUpdate = [...lane.cards, ...newCards]
27+
return update(lane, {cards: {$set: cardsToUpdate}})
2928
}
30-
return update(lane, {cards: {$set: cards}})
3129
} else {
3230
return lane
3331
}

stories/Realtime.story.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class RealtimeBoard extends Component {
1515
}
1616

1717
completeMilkEvent = () => {
18+
this.state.eventBus.publish({type: 'REMOVE_CARD', laneId: 'PLANNED', cardId: 'Milk'})
1819
this.state.eventBus.publish({
1920
type: 'ADD_CARD',
2021
laneId: 'COMPLETED',
2122
card: {id: 'Milk', title: 'Buy Milk', label: '15 mins', description: 'Use Headspace app'}
2223
})
23-
this.state.eventBus.publish({type: 'REMOVE_CARD', laneId: 'PLANNED', cardId: 'Milk'})
2424
}
2525

2626
addBlockedEvent = () => {
@@ -49,12 +49,21 @@ class RealtimeBoard extends Component {
4949
this.setState({boardData: newData})
5050
}
5151

52+
prioritizeWriteBlog = () => {
53+
this.state.eventBus.publish({
54+
type: 'MOVE_CARD',
55+
fromLaneId: 'PLANNED',
56+
toLaneId: 'WIP',
57+
cardId: 'Plan3',
58+
index: 0
59+
})
60+
}
61+
5262
shouldReceiveNewData = nextData => {
5363
console.log('data has changed')
5464
console.log(nextData)
5565
}
5666

57-
5867
render() {
5968
return <div>
6069
<button onClick={this.completeMilkEvent} style={{margin: 5}}>
@@ -68,7 +77,10 @@ class RealtimeBoard extends Component {
6877
</button>
6978
<button onClick={this.modifyCardTitle} style={{margin: 5}}>
7079
Modify Card Title
71-
</button>
80+
</button>
81+
<button onClick={this.prioritizeWriteBlog} style={{margin: 5}}>
82+
Prioritize Write Blog
83+
</button>
7284
<Board data={this.state.boardData} onDataChange={this.shouldReceiveNewData}
7385
eventBusHandle={this.setEventBus} />
7486
</div>

0 commit comments

Comments
 (0)