8 |
9 | Overall Rankings
10 |
11 |
12 |
13 |
14 |
19 |
20 |
21 |
22 |
29 |
30 |
31 |
32 |
33 | props.draft(p)}
37 | />
38 |
39 |
40 | )
41 | }
42 |
43 | UndraftedAll.propTypes = {
44 | players: React.PropTypes.array.isRequired,
45 | format: React.PropTypes.string.isRequired,
46 | query: React.PropTypes.string.isRequired,
47 | search: React.PropTypes.func.isRequired,
48 | fetch: React.PropTypes.func.isRequired,
49 | };
50 |
51 | export default UndraftedAll
52 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 | Top Picks By Position
12 |
13 |
14 |
15 | Runningbacks
16 | props.draft(p)}
20 | size={15}
21 | position='RB'
22 | />
23 |
24 |
25 |
26 | Wide Receivers
27 | props.draft(p)}
31 | size={15}
32 | position='WR'
33 | />
34 |
35 |
36 |
37 | Quarterbacks
38 | props.draft(p)}
42 | size={15}
43 | position='QB'
44 | />
45 |
46 |
47 |
48 | Tightends
49 | props.draft(p)}
53 | size={15}
54 | position='TE'
55 | />
56 |
57 |
58 | )
59 | }
60 |
61 | UndraftedPositions.propTypes = {
62 | draft: React.PropTypes.func.isRequired,
63 | players: React.PropTypes.array.isRequired,
64 | };
65 |
66 | export default UndraftedPositions
67 |
--------------------------------------------------------------------------------
/src/DraftBoard.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 |
3 | import UndraftedAll from './UndraftedAll'
4 | import UndraftedPositions from './UndraftedPositions'
5 | import Drafted from './Drafted'
6 |
7 | class DraftBoard extends Component {
8 | constructor() {
9 | super();
10 |
11 | this.state = {
12 | players: [],
13 | filteredPlayers: [],
14 | isLoading: true,
15 | currentDraft: 0,
16 | fetchError: null,
17 | format: 'standard',
18 | query: '',
19 | };
20 | }
21 |
22 | componentDidMount() {
23 | this.fetchPlayers(this.state.format);
24 | }
25 |
26 | fetchPlayers(format) {
27 | // const url = 'https://draftaid-api.herokuapp.com/rankings';
28 | const url = 'https://jayzheng-ff-api.herokuapp.com/rankings';
29 | const self = this;
30 |
31 | fetch(url+'?format='+format, {
32 | method: 'get'
33 | }).then(function(response) {
34 | response.json().then(function(res){
35 | self.setState({
36 | players: res.rankings,
37 | filteredPlayers: res.rankings,
38 | isLoading: false,
39 | format: format,
40 | query: '',
41 | });
42 | });
43 | }).catch(function(err) {
44 | self.setState({
45 | fetchError: err,
46 | isLoading: false,
47 | });
48 | });
49 | }
50 |
51 | searchPlayers(query) {
52 | let players = this.state.players.filter(player =>
53 | player.name.toUpperCase().includes(query.toUpperCase())
54 | );
55 |
56 | this.setState({
57 | filteredPlayers: players,
58 | query: query,
59 | });
60 | }
61 |
62 | draft(player) {
63 | const players = this.state.players.slice();
64 | const index = players.indexOf(player);
65 | if (~index) {
66 | players[index].drafted = this.state.currentDraft + 1;
67 | }
68 |
69 | this.setState({
70 | currentDraft: this.state.currentDraft + 1,
71 | players: players,
72 | filteredPlayers: players,
73 | query: '',
74 | });
75 | }
76 |
77 | undo(currentDraft) {
78 | if(currentDraft === 0) {
79 | return
80 | }
81 |
82 | const players = this.state.players.slice();
83 | const index = players.findIndex(p => p.drafted === currentDraft);
84 | if (~index) {
85 | players[index].drafted = null;
86 | }
87 |
88 | this.setState({
89 | currentDraft: this.state.currentDraft - 1,
90 | players: players,
91 | });
92 | }
93 |
94 | reset() {
95 | const players = this.state.players.slice();
96 | players.map((player, i) => {
97 | return player.drafted = null;
98 | });
99 |
100 | this.setState({
101 | currentDraft: 0,
102 | players: players,
103 | });
104 | }
105 |
106 | render() {
107 | if (this.state.isLoading) {
108 | return (Loading...
)
109 | }
110 |
111 | if (this.state.fetchError) {
112 | return (error fetching rankings...
)
113 | }
114 |
115 | return (
116 |