diff --git a/src/actions/PlayersActions.js b/src/actions/PlayersActions.js
index 8f427c2..ec7e1e9 100755
--- a/src/actions/PlayersActions.js
+++ b/src/actions/PlayersActions.js
@@ -1,22 +1,35 @@
import * as types from '../constants/ActionTypes';
export function addPlayer(name) {
- return {
- type: types.ADD_PLAYER,
- name,
- };
+ return {
+ type: types.ADD_PLAYER,
+ name,
+ };
}
-export function deletePlayer(id) {
- return {
- type: types.DELETE_PLAYER,
- id,
- };
+export function deletePlayer(name) {
+ return {
+ type: types.DELETE_PLAYER,
+ name,
+ };
}
export function starPlayer(id) {
- return {
- type: types.STAR_PLAYER,
- id,
- };
+ return {
+ type: types.STAR_PLAYER,
+ id,
+ };
+}
+
+export function selectPosition(value) {
+ return {
+ type: types.SELECT_PLAYER,
+ position: value
+ }
+}
+export function currentPageChange(current){
+ return {
+ type:types.CURRENT_PAGE,
+ current:current
+ }
}
diff --git a/src/components/AddPlayerInput.js b/src/components/AddPlayerInput.js
index 5d914d8..927b516 100755
--- a/src/components/AddPlayerInput.js
+++ b/src/components/AddPlayerInput.js
@@ -31,7 +31,12 @@ class AddPlayerInput extends Component {
handleSubmit(e) {
const name = e.target.value.trim();
+ const {playersByIdList} =this.props
if (e.which === 13) {
+ // 应为通过名称来匹配删除,所以名称不可重复
+ if(playersByIdList.some((item,index)=>item.name===name)){
+ return alert('名称不可重复')
+ }
this.props.addPlayer(name);
this.setState({ name: '' });
}
@@ -40,6 +45,8 @@ class AddPlayerInput extends Component {
AddPlayerInput.propTypes = {
addPlayer: PropTypes.func.isRequired,
+ playersByIdList: PropTypes.array.isRequired,
+
};
export default AddPlayerInput;
diff --git a/src/components/Pagination.js b/src/components/Pagination.js
new file mode 100644
index 0000000..ff8584f
--- /dev/null
+++ b/src/components/Pagination.js
@@ -0,0 +1,50 @@
+import React from "react";
+import {currentPageChange} from "../actions/PlayersActions";
+import {connect} from "react-redux";
+import PropTypes from "prop-types";
+import AddPlayerInput from "./AddPlayerInput";
+
+function Pagination(props) {
+ const {
+ playerList: {currentPage}, playersList
+ } = props
+
+ function topPage() {
+ if (currentPage === 1) return
+ props.currentPageChange(currentPage - 1)
+ }
+
+ function btmPage() {
+ if (Math.ceil(playersList.length / 5) === currentPage) return
+ props.currentPageChange(currentPage + 1)
+ }
+
+ let list = props.playersList.map((item, index) => {
+ return Math.ceil((index + 1) / 5)
+ })
+ list = list?.length ? [...new Set(list)] : []
+
+ return (
+
+ {`<`}
+ {list?.map((item, index) => {
+ return {
+ props.currentPageChange(item)
+ }
+ }>{item}
+
+ })}
+ {`>`}
+
+ )
+}
+export default connect(({playerList}) => ({playerList}), {
+ currentPageChange
+})(Pagination)
\ No newline at end of file
diff --git a/src/components/PlayerListItem.js b/src/components/PlayerListItem.js
index ec9758c..457e14a 100755
--- a/src/components/PlayerListItem.js
+++ b/src/components/PlayerListItem.js
@@ -19,7 +19,7 @@ class PlayerListItem extends Component {