image-manager.js
1.35 KB
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
class ImageList extends React.Component {
constructor(props) {
super(props);
this.state = {
images: [],
hasMore: false,
page: 0
};
}
componentDidMount() {
$.getJSON('/images/all', data => {
this.setState({
images: data.images,
hasMore: data.hasMore
});
});
}
loadMore() {
this.state.page++;
$.getJSON('/images/all/' + this.state.page, data => {
this.setState({
images: this.state.images.concat(data.images),
hasMore: data.hasMore
});
});
}
render() {
var images = this.state.images.map(function(image) {
return (
<div key={image.id}>
<img src={image.thumbnail}/>
</div>
);
});
return (
<div className="image-list">
{images}
<div className="load-more" onClick={this.loadMore}>Load More</div>
</div>
);
}
}
class ImageManager extends React.Component {
render() {
return (
<div id="image-manager">
<ImageList/>
</div>
);
}
}
React.render(
<ImageManager />,
document.getElementById('container')
);