-
Notifications
You must be signed in to change notification settings - Fork 0
/
helloworld.html
120 lines (110 loc) · 3.55 KB
/
helloworld.html
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
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<script src="js-lib/jquery-2.1.0.min.js"></script>
<script src="js-lib/pubsub.js"></script>
<script src="build/react.js"></script>
<script src="build/JSXTransformer.js"></script>
<style type="text/css">
#container {
width: 80%;
max-width: 70em;
margin: 0 auto;
}
.BillList {
width: 40%;
float: left;
}
.BillPanel {
width: 58%;
float: right;
}
</style>
</head>
<body>
<div id="container"></div>
<script type="text/jsx">
/** @jsx React.DOM */
var individual_bill_url = "http://api.realtimecongress.org/api/v1/bills.json?apikey=5ee3fecf84784ccf8bfbd61a67c82750&bill_id="
// "Model" Stuff
$.subscribe("/bills/selected/id", function(bill_id) {
$.ajax({
url: individual_bill_url + bill_id,
dataType: 'jsonp',
success: function(data) {
$.publish("/bills/selected/bill", [data.bills[0]]);
},
error: function(xhr, status, err) {
console.error(status, err.toString());
}
});
})
// React Stuff
var Bills = React.createClass({
getInitialState: function() {
return { data: [{question: "Loading. Hold Please."}], selected: 0 };
},
componentWillMount: function() {
$.ajax({
url: this.props.url,
dataType: 'json',
success: function(data) {
this.setState({data: data.results});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
$.subscribe("/bills/selected/bill", function(bill){
this.setState({ selected : bill });
}.bind(this));
},
render: function() {
return (
<div className="Bills">
<BillList data={this.state.data} />
<BillPanel bill={this.state.selected}/>
</div>
)
}
})
var BillList = React.createClass({
render: function() {
var billNodes = this.props.data.map(function (bill, index) {
return <BillEntry key={index} title={bill.question} bill_id={bill.bill_id} />;
});
return <ul className="BillList">{billNodes}</ul>;
}
});
var BillEntry = React.createClass({
handleClick: function(event) {
$.publish("/bills/selected/id", [this.props.bill_id]);
},
render: function() {
return (
<li className="BillEntry" onClick={this.handleClick}>
{this.props.title}
</li>
)
}
});
var BillPanel = React.createClass({
render: function() {
return (
<div>
<h1>{this.props.bill.official_title}</h1>
<div>
<p>state: {this.props.bill.state}</p>
</div>
</div>
)
}
})
React.renderComponent(
<Bills url={"http://congress.api.sunlightfoundation.com/votes?breakdown.total.Yea__gte=200&chamber=house&congress=112&apikey=5ee3fecf84784ccf8bfbd61a67c82750&fields=question,voter_ids,source,url,bill_id"} />,
document.getElementById('container')
);
//http://api.realtimecongress.org/api/v1/bills.json?apikey=5ee3fecf84784ccf8bfbd61a67c82750&callback=jQuery18308469967732193624_1393206398376&bill_id=hr3606-112&_=1393206398947
</script>
</body>
</html>