-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormation.js
117 lines (99 loc) · 2.96 KB
/
Formation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {
Dropdown,
Grid,
Header,
Transition,
} from 'semantic-ui-react';
import FormationRowPlayers from '../../display/FormationRowPlayers';
import Position from '../../../globals/constants/Position';
import appThunks from '../../../actions/appThunks';
class Formation extends Component {
static propTypes = {
formations : PropTypes.array,
loadFormations : PropTypes.func.isRequired,
};
static defaultProps = { formations: [] };
state = { formation: '4-4-2' }
componentDidMount() {
this.props.loadFormations();
}
handleFormationSet = (e,data) => {
this.setState({ formation: data.value });
}
render() {
const { formations } = this.props;
const formationsOptions = formations.map((f) => ({
key : f,
text : f,
value : f,
})); // Semantic Ui Dropdown requires options formatted with these three values
const forwards = [null, 9, 24];
const midfielders = [11,null,null,19];
const defenders = [18,6,null,24];
const keeper = [33];
const { formation } = this.state;
const rows = formation.split('-').map(Number);
return (
<Transition
animation='fade'
duration={300}
transitionOnMount
>
<Grid
data-component='Formation'
padded
>
<Grid.Row>
<Grid.Column width={12}>
<Header content='Formation' />
</Grid.Column>
<Grid.Column
textAlign='right'
width={4}
>
<Dropdown
onChange={this.handleFormationSet}
options={formationsOptions}
text={formation}
value={formation}
/>
</Grid.Column>
</Grid.Row>
{/* NOTE: This is the FWD row */}
<FormationRowPlayers
maxPlayers={rows[2]}
players={forwards}
position={Position[0]}
/>
{/* NOTE: This is the MID row */}
<FormationRowPlayers
maxPlayers={rows[1]}
players={midfielders}
position={Position[1]}
/>
{/* NOTE: This is the DEF row */}
<FormationRowPlayers
maxPlayers={rows[0]}
players={defenders}
position={Position[2]}
/>
{/* NOTE: This is the GOL row */}
<FormationRowPlayers
players={keeper}
position={Position[3]}
/>
</Grid>
</Transition>
);
}
}
const mapDispatchToProps = (dispatch) => ({
loadFormations: () => {
dispatch(appThunks.loadFormations());
},
});
const mapStateToProps = (state) => ({ formations: state.formations });
export default connect(mapStateToProps, mapDispatchToProps)(Formation);