Created
October 5, 2018 03:33
-
-
Save carloszan/42f829cf5a96372a3bf0999ad4ec4491 to your computer and use it in GitHub Desktop.
doubt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import MatchList from './MatchList.js'; | |
import SearchMatch from './SearchMatch.js' | |
const Matchs = [{ | |
key: 1, | |
home: 'Cruzeiro', | |
away: 'Palmeiras', | |
home_score: '3', | |
away_score: '0' | |
}, | |
{ | |
key: 2, | |
home: 'Atletico-MG', | |
away: 'Vasco', | |
home_score: '9', | |
away_score: '2' | |
}]; | |
class MatchDashboard extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
matchs: Object.assign([], Matchs) | |
}; | |
} | |
filterTeam = (event) => { | |
console.log(event.target.value); | |
if(event.target.value == '') | |
this.setState({ matchs: Matchs }); | |
const filtered = this.state.matchs.filter((team) => { | |
const home = team.home.toLowerCase(); | |
const away = team.away.toLowerCase(); | |
const teamName = event.target.value; | |
return (!home.indexOf(teamName.toLowerCase()) || | |
!away.indexOf(teamName.toLowerCase())); | |
}); | |
this.setState({ matchs: filtered }); | |
} | |
render() { | |
return ( | |
<div> | |
<SearchMatch filterTeam={ this.filterTeam }/> | |
<MatchList { ...this.state } /> | |
</div> | |
); | |
} | |
} | |
export default MatchDashboard; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
class SearchMatch extends Component { | |
render() { | |
return ( | |
<div className="ui search"> | |
<div className="ui icon input"> | |
<input className="prompt" type="text" placeholder="Pesquisar times..." onChange={ this.props.filterTeam }/> | |
<i className="search icon"></i> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default SearchMatch; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment