Skip to content

lx提交 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -9,6 +9,7 @@
"eject": "react-scripts eject"
},
"dependencies": {
"antd": "^4.0.2",
"classnames": "^2.2.6",
"lodash": "^4.17.15",
"prop-types": "^15.7.2",
Expand All @@ -18,7 +19,14 @@
"redux": "^4.0.5"
},
"devDependencies": {
"antd": "^4.0.2",
"babel-plugin-import": "^1.13.0",
"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"
]
}
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="../node_modules/antd/dist/antd.css">
<!--
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Expand Down
6 changes: 6 additions & 0 deletions src/actions/PlayersActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ export function starPlayer(id) {
id,
};
}

export function clearData() {
return {
type: types.CLEAR_DATA,
};
}
2 changes: 2 additions & 0 deletions src/components/PlayerList.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class PlayerList extends Component {
/>
);
})}


</ul>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/constants/ActionTypes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const ADD_PLAYER = 'ADD_PLAYER';
export const STAR_PLAYER = 'STAR_PLAYER';
export const DELETE_PLAYER = 'DELETE_PLAYER';
export const CLEAR_DATA = 'CLEAR_DATA';
43 changes: 37 additions & 6 deletions src/containers/PlayerListApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,59 @@ 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 ,clearData} from '../actions/PlayersActions';
import { PlayerList, AddPlayerInput } from '../components';
import { Pagination,Button } from 'antd';


class PlayerListApp extends Component {
constructor(props,context){
super()
this.state = {
playersById: props.playerlist.playersById.slice(0,5)
}
}
render() {
const {
playerlist: { playersById },
} = this.props;

let list = this.props.playerlist.playersById;
const actions = {
addPlayer: this.props.addPlayer,
deletePlayer: this.props.deletePlayer,
starPlayer: this.props.starPlayer,
};

let onChange = (ev)=>{
let ye = ev - 1;
let first = ye * 5;
let end = first + 5;
if(first-1 < 0){
first = 1;
end = 6;
}
this.setState({
playersById : list.slice(first-1,end-1)
})
}

let clear = ()=>{
this.setState({
playersById : []
})
}

return (
<div className={styles.playerListApp}>
<h1>NBA Players</h1>

<AddPlayerInput addPlayer={actions.addPlayer} />
<PlayerList players={playersById} actions={actions} />

<PlayerList players={this.state.playersById} actions={actions} />

<Button onClick = {clear}>清空当前页</Button>
<Pagination defaultCurrent={1} total={40} onChange={onChange} />
</div>
);
}

}

function mapStateToProps(state) {
Expand All @@ -37,5 +67,6 @@ export default connect(
addPlayer,
deletePlayer,
starPlayer,
clearData
},
)(PlayerListApp);
54 changes: 52 additions & 2 deletions src/reducers/playerlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import * as types from '../constants/ActionTypes';
const initialState = {
playersById: [
{
name: 'LeBron James',
name: '1LeBron James',
team: 'LOS ANGELES LAKERS',
position: 'SF',
starred: true,
},
{
name: 'Kevin Duran',
name: '2Kevin Duran',
team: 'GOLDEN STATE WARRIORS',
position: 'SF',
starred: false,
Expand Down Expand Up @@ -38,6 +38,52 @@ const initialState = {
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,
},{
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,
}
],
};

Expand Down Expand Up @@ -70,6 +116,10 @@ export default function players(state = initialState, action) {
...state,
playersById: players,
};
case types.CLEAR_DATA:
return {
playersById: {},
};

default:
return state;
Expand Down