Last active
March 20, 2016 16:48
-
-
Save leofrozenyogurt/3765b3ffa2cff7b92741 to your computer and use it in GitHub Desktop.
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
var AgenciesContainer = React.createClass({ | |
componentWillMount(){ | |
this.fetchAgencies(); | |
}, | |
fetchAgencies() { | |
$.ajax({ | |
url: this.props.agenciesPath, | |
dataType: 'json', | |
success: function(data) { | |
this.setState({agencies: data}); | |
}.bind(this), | |
error: function(data) { | |
this.setState({agencies: []}); | |
}.bind(this) | |
}); | |
}, | |
searchAgencies(event) { | |
if (event.target.value) { | |
$.ajax({ | |
url: this.props.searchPath+"?query="+event.target.value, | |
dataType: 'json', | |
success: function(data) { | |
this.setState({agencies: data}); | |
}.bind(this), | |
error: function(data) { | |
this.setState({agencies: []}); | |
}.bind(this) | |
}); | |
} | |
else{ | |
this.fetchAgencies(); | |
} | |
history.pushState("search: searched", null, this.props.searchPath+"?query="+event.target.value) | |
}, | |
renderAgency(){ | |
console.log("rendered"); | |
this.setState({hidden: ""}) | |
}, | |
getInitialState() { | |
return { agencies: [] , hidden: "hidden" , rendered_agencies:[], yolo:"awesome" }; | |
}, | |
render() { | |
return ( | |
<div> | |
<AgencySearch searchPath={this.props.searchPath} submitPath={this.searchAgencies} cancelPath={this.fetchAgencies}/> | |
<Agencies agencies={this.state.agencies} renderAgency={this.renderAgency}/> | |
<AgencyPartial agencies={this.props.rendered_agencies} hidden={this.state.hidden} /> | |
</div> | |
); | |
} | |
}); |
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
var Agencies = React.createClass({ | |
render() { | |
var showAgencies = (agency) => <Agency name={agency.title} key={agency.id} renderAgency={this.props.renderAgency} />; | |
return ( | |
<div className="agencies"> | |
{this.props.agencies.map(showAgencies)} | |
</div> | |
); | |
} | |
}); |
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
var Agency = React.createClass({ | |
handleClick: function(){ | |
this.props.renderAgency; | |
}, | |
render () { | |
return ( | |
<div className="agency"> | |
<img onClick={this.handleClick} src="http://placehold.it/300x300" /> | |
<h4 onClick={this.handleClick}>{this.props.name }</h4> | |
</div> | |
) | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment