diff --git a/docs/src/index.js b/docs/src/index.js index ff7ccee..bb15622 100644 --- a/docs/src/index.js +++ b/docs/src/index.js @@ -3,93 +3,85 @@ import ReactDOM from 'react-dom'; import InfiniteScroll from '../../dist/InfiniteScroll'; import qwest from 'qwest'; -const imageList = []; const api = { - baseUrl: 'https://api.soundcloud.com', - client_id: 'caf73ef1e709f839664ab82bef40fa96' + baseUrl: 'https://api.soundcloud.com', + client_id: 'caf73ef1e709f839664ab82bef40fa96' }; class App extends Component { - constructor(props) { - super(props); + constructor(props) { + super(props); - this.state = { - tracks: [], - hasMoreItems: true, - nextHref: null - }; - } - - loadItems(page) { - var self = this; + this.state = { + tracks: [], + hasMoreItems: true, + nextHref: null + }; + } - var url = api.baseUrl + '/users/8665091/favorites'; - if(this.state.nextHref) { - url = this.state.nextHref; - } - - qwest.get(url, { - client_id: api.client_id, - linked_partitioning: 1, - page_size: 10 - }, { - cache: true - }) - .then(function(xhr, resp) { - if(resp) { - var tracks = self.state.tracks; - resp.collection.map((track) => { - if(track.artwork_url == null) { - track.artwork_url = track.user.avatar_url; - } + loadItems = (page) => { + const url = `${api.baseUrl}/users/8665091/favorites`; + if (this.state.nextHref) { + url = this.state.nextHref; + } - tracks.push(track); - }); + qwest.get(url, { + client_id: api.client_id, + linked_partitioning: 1, + page_size: 10 + }, { + cache: true + }) + .then((xhr, resp) => { + if (resp) { + const tracks = this.state.tracks; + resp.collection.map((track) => { + if (track.artwork_url == null) { + track.artwork_url = track.user.avatar_url; + } + tracks.push(track); + }); - if(resp.next_href) { - self.setState({ - tracks: tracks, - nextHref: resp.next_href - }); - } else { - self.setState({ - hasMoreItems: false - }); - } - } + if (resp.next_href) { + this.setState({ + tracks: tracks, + nextHref: resp.next_href }); - } - - render() { - const loader =
Loading ...
; + } else { + this.setState({ + hasMoreItems: false + }); + } + } + }); + } - var items = []; - this.state.tracks.map((track, i) => { - items.push( -
- - -

{track.title}

-
-
- ); - }); + render() { + const loader =
Loading ...
; - return ( - + const items = this.state.tracks.map((track, i) => { +
+ + +

{track.title}

+
+
+ }); -
- {items} -
-
- ); - } + return ( + +
+ {items} +
+
+ ); + } }; ReactDOM.render( - -, document.getElementById('root')); + + , document.getElementById('root'));