Skip to content

Instantly share code, notes, and snippets.

@leofrozenyogurt
Created March 23, 2016 15:43
Show Gist options
  • Save leofrozenyogurt/3387aaf9794bb4dc31f0 to your computer and use it in GitHub Desktop.
Save leofrozenyogurt/3387aaf9794bb4dc31f0 to your computer and use it in GitHub Desktop.
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(event){
this.setState({hidden: ""});
this.setState({agency_ids: this.state.agency_ids.concat(event.props.id)});
console.log(this.state.agency_ids);
console.log(this.state.hidden);
$.ajax({
url: "compare.json?ids="+this.state.agency_ids,
dataType: 'json',
success: function(data) {
this.setState({rendered_agencies: data});
}.bind(this),
error: function(data) {
this.setState({rendered_agencies: []});
}.bind(this)
});
},
getInitialState() {
return { agencies: [] , hidden: "hidden" , agency_ids:[], rendered_agencies:[], yolo:"awesome" };
},
render() {
return (
<div className="container">
<div className="home-hero text-center">
<h1>
Compare Agency Open Data Requirements
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
</p>
</div>
<AgencySearch searchPath={this.props.searchPath} submitPath={this.searchAgencies} cancelPath={this.fetchAgencies}/>
<Agencies agencies={this.state.agencies} renderAgency={this.renderAgency}/>
<hr></hr>
<div className="row agency-headers text-center">
<AgencyPartial agencies={this.state.rendered_agencies} hidden={this.state.hidden} />
</div>
</div>
);
}
});
var Agency = React.createClass({
handleClick: function(event) {
this.props.renderAgency.bind(null,this);
},
render () {
return (
<div className="agency">
<img onClick={this.props.renderAgency.bind(null,this)} src="http://placehold.it/300x300" />
<h4 onClick={this.props.renderAgency.bind(null,this)}>{this.props.name }</h4>
</div>
)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment