Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@
},
"dependencies": {
"classnames": "^2.2.6",
"element-react": "^1.4.34",
"element-theme-default": "^1.4.13",
"lodash": "^4.17.15",
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-hot-loader": "^4.12.21",
"react-redux": "^7.2.0",
"redux": "^4.0.5"
},
"devDependencies": {
"react-scripts": "3.4.0"
},
"browserslist": [">0.2%", "not dead", "not ie <= 11", "not op_mini all"]
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
8 changes: 8 additions & 0 deletions src/actions/PlayersActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ export function starPlayer(id) {
id,
};
}


export function pageCurrentChangePlayer(currentPage) {
return {
type: types.PAGE_CURRENT_CHANGE_PLAYER,
currentPage,
};
}
34 changes: 22 additions & 12 deletions src/components/PlayerList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ import PropTypes from 'prop-types';
import styles from './PlayerList.css';
import PlayerListItem from './PlayerListItem';

import { Pagination } from 'element-react';


class PlayerList extends Component {
render() {
return (
<div>
<ul className={styles.playerList}>
{this.props.players.map((player, index) => {
return (
<PlayerListItem
key={index}
id={index}
name={player.name}
team={player.team}
position={player.position}
starred={player.starred}
{...this.props.actions}
/>
);
{this.props.players.map((player, index) => {
if(index >= (this.props.currentPage-1)*10 && index < this.props.currentPage * 10){
return (
<PlayerListItem
key={index}
id={index}
name={player.name}
team={player.team}
position={player.position}
starred={player.starred}
{...this.props.actions}
/>
);
}
})}
</ul>
<div>
<Pagination layout="total, prev, pager, next" total={this.props.players.length} onCurrentChange={this.props.actions.pageCurrentChangePlayer}/>
</div>
</div>
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/PlayerListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PlayerListItem extends Component {
<button
className={`btn btn-default ${styles.btnAction}`}
onClick={() => this.props.starPlayer(this.props.id)}
>
>4
<i
className={classnames('fa', {
'fa-star': this.props.starred,
Expand All @@ -32,7 +32,7 @@ class PlayerListItem extends Component {
<button
className={`btn btn-default ${styles.btnAction}`}
onClick={() => this.props.deletePlayer(this.props.id)}
>
> 5
<i className="fa fa-trash" />
</button>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/constants/ActionTypes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const ADD_PLAYER = 'ADD_PLAYER';
export const STAR_PLAYER = 'STAR_PLAYER';
export const DELETE_PLAYER = 'DELETE_PLAYER';

export const PAGE_CURRENT_CHANGE_PLAYER = 'PAGE_CURRENT_CHANGE_PLAYER';
4 changes: 4 additions & 0 deletions src/containers/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import React, { Component } from 'react';


import 'element-theme-default';

import { combineReducers, createStore } from 'redux';
import { Provider } from 'react-redux';

Expand Down
9 changes: 6 additions & 3 deletions src/containers/PlayerListApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ import React, { Component } from 'react';
import styles from './PlayerListApp.css';
import { connect } from 'react-redux';

import { addPlayer, deletePlayer, starPlayer } from '../actions/PlayersActions';
import { addPlayer, deletePlayer, starPlayer,pageCurrentChangePlayer } from '../actions/PlayersActions';

import { PlayerList, AddPlayerInput } from '../components';

class PlayerListApp extends Component {
render() {
const {
playerlist: { playersById },
playerlist: { playersById }
} = this.props;

const actions = {
addPlayer: this.props.addPlayer,
deletePlayer: this.props.deletePlayer,
starPlayer: this.props.starPlayer,
pageCurrentChangePlayer: this.props.pageCurrentChangePlayer
};

return (
<div className={styles.playerListApp}>
<h1>NBA Players</h1>
<AddPlayerInput addPlayer={actions.addPlayer} />
<PlayerList players={playersById} actions={actions} />
<PlayerList players={playersById} currentPage={this.props.playerlist.currentPage} actions={actions} />
</div>
);
}
Expand All @@ -37,5 +39,6 @@ export default connect(
addPlayer,
deletePlayer,
starPlayer,
pageCurrentChangePlayer
},
)(PlayerListApp);
53 changes: 53 additions & 0 deletions src/reducers/playerlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,39 @@ const initialState = {
team: 'TORONTO RAPTORS',
position: 'SF',
starred: false,
},{
name: 'Kawhi Leonard',
team: 'TORONTO RAPTORS',
position: 'SF',
starred: false,
},{
name: 'Kawhi Leonard',
team: 'TORONTO RAPTORS',
position: 'SF',
starred: false,
},{
name: 'Kawhi Leonard',
team: 'TORONTO RAPTORS',
position: 'SF',
starred: false,
},{
name: 'Kawhi Leonard',
team: 'TORONTO RAPTORS',
position: 'SF',
starred: false,
},{
name: 'Kawhi Leonard',
team: 'TORONTO RAPTORS',
position: 'SF',
starred: false,
},{
name: 'Kawhi Leonard',
team: 'TORONTO RAPTORS',
position: 'SF',
starred: false,
},
],
currentPage: 1
};

export default function players(state = initialState, action) {
Expand All @@ -55,13 +86,21 @@ export default function players(state = initialState, action) {
},
],
};



case types.DELETE_PLAYER:
return {
...state,
playersById: state.playersById.filter(
(item, index) => index !== action.id,
),
};





case types.STAR_PLAYER:
let players = [...state.playersById];
let player = players.find((item, index) => index === action.id);
Expand All @@ -71,6 +110,20 @@ export default function players(state = initialState, action) {
playersById: players,
};



case types.PAGE_CURRENT_CHANGE_PLAYER:

let curPage = action.currentPage;

return {
...state,
currentPage: curPage
};




default:
return state;
}
Expand Down