-
Notifications
You must be signed in to change notification settings - Fork 310
/
app.js
85 lines (81 loc) · 2.9 KB
/
app.js
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
import React from 'react';
import ReactDOM from 'react-dom';
import jsonp from 'jsonp';
import ExampleBasic from './ExampleBasic';
import ExampleWithLightbox from './ExampleWithLightbox';
import ExampleCustomComponentSelection from './ExampleCustomComponentSelection';
import ExampleSortable from './ExampleSortable';
import ExampleDynamicLoading from './ExampleDynamicLoading';
import ExampleDynamicColumns from './ExampleDynamicColumns';
class App extends React.Component {
constructor() {
super();
this.state = { width: -1 };
this.loadPhotos = this.loadPhotos.bind(this);
}
componentDidMount() {
this.loadPhotos();
}
loadPhotos() {
const urlParams = {
api_key: '455b5e2fa6b951f9b9ab58a86d5e1f8a',
photoset_id: '72157708141247864',
user_id: '146659101@N08',
format: 'json',
per_page: '120',
extras: 'url_m,url_c,url_l,url_h,url_o',
};
let url = 'https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos';
url = Object.keys(urlParams).reduce((acc, item) => {
return acc + '&' + item + '=' + urlParams[item];
}, url);
jsonp(url, { name: 'jsonFlickrApi' }, (err, data) => {
let photos = data.photoset.photo.map(item => {
let aspectRatio = parseFloat(item.width_o / item.height_o);
return {
src: item.url_l,
width: parseInt(item.width_o),
height: parseInt(item.height_o),
title: item.title,
alt: item.title,
key: item.id,
srcSet: [
`${item.url_m} ${item.width_m}w`,
`${item.url_c} ${item.width_c}w`,
`${item.url_l} ${item.width_l}w`,
`${item.url_h} ${item.width_h}w`,
],
sizes: '(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw',
};
});
this.setState({
photos: this.state.photos ? this.state.photos.concat(photos) : photos,
});
});
}
render() {
if (this.state.photos) {
const width = this.state.width;
return (
<div className="App">
<ExampleBasic title={'Basic Row Layout'} photos={this.state.photos.slice(0, 20)} />
<ExampleBasic title={'Basic Column Layout'} direction="column" photos={this.state.photos.slice(40, 60)} />
<ExampleWithLightbox photos={this.state.photos.slice(60, 75)} />
<ExampleCustomComponentSelection photos={this.state.photos.slice(75, 90)} />
<ExampleSortable photos={this.state.photos.slice(90, 100)} />
<ExampleDynamicColumns title={'Custom Dynamic Columns'} photos={this.state.photos.slice(100, 120)} />
<ExampleDynamicLoading photos={this.state.photos} />
</div>
);
} else {
return (
<div className="App">
<div id="msg-app-loading" className="loading-msg">
Loading
</div>
</div>
);
}
}
}
ReactDOM.render(<App />, document.getElementById('app'));