Last active
February 29, 2016 20:09
-
-
Save yoamomonstruos/25cf531346f88db8e504 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { bindActionCreators } from 'redux'; | |
import { connect } from 'react-redux'; | |
import Helmet from 'react-helmet'; | |
import * as BoardsActions from '../actions/boards-actions'; | |
import BoardList from '../components/boardList'; | |
class Boards extends Component { | |
constructor(props) { | |
super(props); | |
} | |
componentDidMount () { | |
const { requestBoards } = this.props; | |
requestBoards(); | |
} | |
render () { | |
return (<BoardList {...this.props} />) | |
} | |
} | |
function mapStateToProps (state) { | |
return { | |
boards: state.boards | |
} | |
} | |
function mapDispatchToProps(dispatch) { | |
return bindActionCreators(BoardsActions, dispatch); | |
} | |
export default connect(mapStateToProps, mapDispatchToProps)(Boards); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
REQUEST_BOARDS_SUCCESS, | |
CREATE_BOARD_SUCCESS, | |
DELETE_BOARD_SUCCESS, | |
UPDATE_BOARD_SUCCESS, | |
UPDATE_TASK_SUCCESS | |
} from '../types/boards-types'; | |
export const initialState = { | |
deleted: null, | |
list: [], | |
previous: [] | |
}; | |
export function boardsReducer(state = initialState, action) { | |
switch (action.type) { | |
case REQUEST_BOARDS_SUCCESS: | |
return { | |
deleted: state.deleted, | |
list: action.payload, | |
previous: state.previous | |
}; | |
break; | |
case CREATE_BOARD_SUCCESS: | |
return { | |
deleted: state.deleted, | |
list: [ action.payload, ...state.list ], | |
previous: state.previous | |
}; | |
break; | |
case UPDATE_BOARD_SUCCESS: | |
return { | |
deleted: state.deleted, | |
list: state.list.map(board => { | |
return board.id === action.payload.id ? action.payload : board; | |
}), | |
previous: state.previous | |
} | |
break; | |
case DELETE_BOARD_SUCCESS: | |
return { | |
deleted: action.payload, | |
list: state.list.filter(board => { | |
return board.id !== action.payload | |
}), | |
previous: [ ...state.list ] | |
} | |
break; | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment