Skip to content

Commit

Permalink
Merge branch 'orangecoding-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rcdexta committed Feb 12, 2018
2 parents 6c8e81f + 5ecf647 commit 5479819
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ eventBus.publish({type: 'ADD_CARD', laneId: 'COMPLETED', card: {id: "M1", title:
//To remove a card
eventBus.publish({type: 'REMOVE_CARD', laneId: 'PLANNED', cardId: "M1"})

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

<Board data={data} eventBusHandle={setEventBus}/>
```

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.
Expand Down
4 changes: 3 additions & 1 deletion src/components/BoardContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class BoardContainer extends Component {
return actions.removeCard({laneId: event.laneId, cardId: event.cardId})
case 'REFRESH_BOARD':
return actions.loadBoard(event.data)
case 'MOVE_CARD':
return actions.moveCardAcrossLanes({fromLaneId: event.fromLaneId, toLaneId: event.toLaneId, cardId: event.cardId, index: event.index})
}
}
}
Expand Down Expand Up @@ -96,7 +98,7 @@ class BoardContainer extends Component {
const {id, droppable, ...otherProps} = lane
return (
<Lane
key={`${id}`}
key={id}
id={id}
index={index}
droppable={droppable === undefined ? true : droppable}
Expand Down
10 changes: 0 additions & 10 deletions src/components/Lane.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ class Lane extends Component {
}
}

moveCardAcrossLanes = (fromLaneId, toLaneId, cardId) => {
toLaneId &&
this.props.actions.moveCardAcrossLanes({
fromLaneId: fromLaneId,
toLaneId: toLaneId,
cardId: cardId
})
}

removeCard = (laneId, cardId) => {
this.props.actions.removeCard({laneId: laneId, cardId: cardId})
}
Expand Down Expand Up @@ -158,7 +149,6 @@ class Lane extends Component {
tagStyle={tagStyle}
cardStyle={cardStyle}
moveCard={this.moveCard}
moveCardAcrossLanes={this.moveCardAcrossLanes}
removeCard={this.removeCard}
onClick={e => this.handleCardClick(e, card)}
onDelete={this.props.onCardDelete}
Expand Down
3 changes: 0 additions & 3 deletions src/helpers/DragType.js

This file was deleted.

8 changes: 3 additions & 5 deletions src/helpers/LaneHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ const LaneHelper = {
newCards = newCards.map(c => update(c, {laneId: {$set: laneId}}))
return state.lanes.map(lane => {
if (lane.id === laneId) {
let cards = null
if (index !== undefined) {
cards = lane.cards
cards.splice(index, 0, ...newCards)
return update(lane, {cards: {$splice: [[index, 0, ...newCards]]}})
} else {
cards = [...lane.cards, ...newCards]
const cardsToUpdate = [...lane.cards, ...newCards]
return update(lane, {cards: {$set: cardsToUpdate}})
}
return update(lane, {cards: {$set: cards}})
} else {
return lane
}
Expand Down
18 changes: 15 additions & 3 deletions stories/Realtime.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class RealtimeBoard extends Component {
}

completeMilkEvent = () => {
this.state.eventBus.publish({type: 'REMOVE_CARD', laneId: 'PLANNED', cardId: 'Milk'})
this.state.eventBus.publish({
type: 'ADD_CARD',
laneId: 'COMPLETED',
card: {id: 'Milk', title: 'Buy Milk', label: '15 mins', description: 'Use Headspace app'}
})
this.state.eventBus.publish({type: 'REMOVE_CARD', laneId: 'PLANNED', cardId: 'Milk'})
}

addBlockedEvent = () => {
Expand Down Expand Up @@ -49,12 +49,21 @@ class RealtimeBoard extends Component {
this.setState({boardData: newData})
}

prioritizeWriteBlog = () => {
this.state.eventBus.publish({
type: 'MOVE_CARD',
fromLaneId: 'PLANNED',
toLaneId: 'WIP',
cardId: 'Plan3',
index: 0
})
}

shouldReceiveNewData = nextData => {
console.log('data has changed')
console.log(nextData)
}


render() {
return <div>
<button onClick={this.completeMilkEvent} style={{margin: 5}}>
Expand All @@ -68,7 +77,10 @@ class RealtimeBoard extends Component {
</button>
<button onClick={this.modifyCardTitle} style={{margin: 5}}>
Modify Card Title
</button>
</button>
<button onClick={this.prioritizeWriteBlog} style={{margin: 5}}>
Prioritize Write Blog
</button>
<Board data={this.state.boardData} onDataChange={this.shouldReceiveNewData}
eventBusHandle={this.setEventBus} />
</div>
Expand Down

0 comments on commit 5479819

Please sign in to comment.