diff --git a/src/actions/PlayersActions.js b/src/actions/PlayersActions.js
index 8f427c2..b68af50 100755
--- a/src/actions/PlayersActions.js
+++ b/src/actions/PlayersActions.js
@@ -1,9 +1,9 @@
import * as types from '../constants/ActionTypes';
-export function addPlayer(name) {
+export function addPlayer(info) {
return {
type: types.ADD_PLAYER,
- name,
+ info,
};
}
diff --git a/src/components/AddPlayerInput.js b/src/components/AddPlayerInput.js
index 5d914d8..7692d75 100755
--- a/src/components/AddPlayerInput.js
+++ b/src/components/AddPlayerInput.js
@@ -31,9 +31,11 @@ class AddPlayerInput extends Component {
handleSubmit(e) {
const name = e.target.value.trim();
+ if (!name) return
if (e.which === 13) {
- this.props.addPlayer(name);
- this.setState({ name: '' });
+ this.setState({ name: '' }, () => {
+ this.props.onsubmit(name)
+ });
}
}
}
diff --git a/src/components/AddPositionRadio.js b/src/components/AddPositionRadio.js
new file mode 100644
index 0000000..44cd499
--- /dev/null
+++ b/src/components/AddPositionRadio.js
@@ -0,0 +1,47 @@
+import React, { Component } from 'react';
+class AddPositionRadio extends Component {
+ constructor(props, context) {
+ super(props, context);
+ this.state = {
+ currentValue: this.props.startPosition || 'SF'
+ }
+ }
+
+ handleChange = position => {
+ this.setState({
+ currentValue: position
+ }, () => {
+ this.props.onpositionchange(position)
+ })
+ }
+
+ render() {
+ const currentValue = this.state.currentValue
+ return (
+
+
+
+
+ )
+ }
+}
+
+export default AddPositionRadio;
diff --git a/src/components/Pagination.css b/src/components/Pagination.css
new file mode 100644
index 0000000..48eacc9
--- /dev/null
+++ b/src/components/Pagination.css
@@ -0,0 +1,12 @@
+.pagination {
+ margin: 0;
+
+}
+.pagination li {
+ padding: 4px 10px;
+ border: 1px solid aqua;
+ margin-right: 10px;
+}
+.pagination li.selected {
+ background-color: aqua;
+}
\ No newline at end of file
diff --git a/src/components/Pagination.js b/src/components/Pagination.js
new file mode 100644
index 0000000..6078c8e
--- /dev/null
+++ b/src/components/Pagination.js
@@ -0,0 +1,35 @@
+
+import React, { Component } from 'react';
+import './Pagination.css';
+
+class Pagination extends Component {
+ handleClick = e => {
+ const pageNum = e.target.dataset.page
+ if (pageNum) {
+ this.props.onselected(pageNum)
+ }
+ }
+ render() {
+ const {pageCounts, currentPage} = this.props
+ const pageList = [...Array(pageCounts)]
+ return (
+
+ {pageList.map((item, index) => {
+ let page = index + 1
+ return (
+ -
+ {page}
+
+ )
+ })}
+
+ );
+ }
+}
+
+export default Pagination;
diff --git a/src/components/PlayerList.js b/src/components/PlayerList.js
index 7b40246..bc30263 100755
--- a/src/components/PlayerList.js
+++ b/src/components/PlayerList.js
@@ -11,7 +11,7 @@ class PlayerList extends Component {
return (
{
+ pageNum = +pageNum
+ if (this.state.currentPage !== pageNum) {
+ this.setState({
+ currentPage: pageNum
+ })
+ }
+ }
+ handlePositionChange = position => {
+ this.currentPosition = position
+ }
+ handlePlayerAdd = player => {
+ this.props.addPlayer({
+ name: player,
+ position: this.currentPosition
+ })
+ }
render() {
const {
playerlist: { playersById },
} = this.props;
+ const pageCounts = Math.ceil(playersById.length / this.playsPerPage)
+ const { currentPage } = this.state
+ const currentList = playersById.slice((currentPage-1)*this.playsPerPage, currentPage*this.playsPerPage)
const actions = {
addPlayer: this.props.addPlayer,
deletePlayer: this.props.deletePlayer,
@@ -20,8 +48,24 @@ class PlayerListApp extends Component {
return (
);
}
diff --git a/src/reducers/playerlist.js b/src/reducers/playerlist.js
index 1bc7457..b3d385a 100755
--- a/src/reducers/playerlist.js
+++ b/src/reducers/playerlist.js
@@ -49,9 +49,8 @@ export default function players(state = initialState, action) {
playersById: [
...state.playersById,
{
- name: action.name,
team: 'LOS ANGELES LAKERS',
- position: 'SF',
+ ...action.info
},
],
};
@@ -63,6 +62,7 @@ export default function players(state = initialState, action) {
),
};
case types.STAR_PLAYER:
+ debugger
let players = [...state.playersById];
let player = players.find((item, index) => index === action.id);
player.starred = !player.starred;