-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·66 lines (65 loc) · 2.58 KB
/
index.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
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset='utf-8'>
<title>GitHub as public datastore</title>
<script src="https://npmcdn.com/[email protected]/browser-polyfill.min.js" charset="utf-8"></script>
<script src="https://npmcdn.com/[email protected]/browser.min.js" charset="utf-8"></script>
<script src="https://npmcdn.com/[email protected]/dist/react.js" charset="utf-8"></script>
<script src="https://npmcdn.com/[email protected]/dist/react-dom.js" charset="utf-8"></script>
<script src="https://npmcdn.com/[email protected]/superagent.js"></script>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="react-root"></div>
<script type="text/babel">
"use strict";
class SearchExample extends React.Component {
constructor(props) {
super(props)
this.state = {
searchString: '',
items: []
}
}
componentWillMount(){
var request = window.superagent;
var self = this;
request
.get('api/members.json')
.end(function(err, res){
if(!err) {
self.setState({items: res.body});
} else {
console.log(err)
}
})
}
handleChange(e){
this.setState({searchString:e.target.value});
}
render() {
var items = this.state.items;
var searchString = this.state.searchString.trim().toLowerCase();
if(searchString.length > 0){
items = items.filter(function(l){
return l.name.toLowerCase().match( searchString );
});
}
return (
<div>
<p>update by editing <a href="https://github.com/pe3/data-repo-test/blob/gh-pages/_data/members.yml">yaml file</a></p>
<input type="text" value={this.state.searchString} onChange={this.handleChange.bind(this)} placeholder="Type here" />
<ul>
{ items.map(function(l,i){
return <li key={i}>{l.name} <a href={l.url}>{l.url}</a></li>
}) }
</ul>
</div>
)
}
}
ReactDOM.render(<SearchExample />, document.querySelector('#react-root'));
</script>
</body>
</html>