2015-07-27 20:49:37 +02:00
|
|
|
import React from 'react';
|
|
|
|
import Box from '../partials/box';
|
|
|
|
import Api from '../api';
|
|
|
|
|
|
|
|
class Home extends React.Component {
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.loadHomeItems();
|
2016-02-23 09:11:31 +01:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
items: []
|
|
|
|
};
|
2015-07-27 20:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let boxes = this.state.items.map((value, key) => {
|
2015-07-28 20:50:39 +02:00
|
|
|
return <Box items={value.items} category={value.category} key={key} type="home" currentLoaded="5" />
|
2015-07-27 20:49:37 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<div>
|
|
|
|
{ ! this.state.items.length ? <i className="icon-content-load"></i> : boxes}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
loadHomeItems() {
|
|
|
|
let items = [];
|
|
|
|
let requests = [];
|
|
|
|
let self = this;
|
|
|
|
|
|
|
|
Api.categories().then((value) => {
|
|
|
|
value.forEach((data) => {
|
|
|
|
requests.push($.get(config.api + 'home-items/' + data.slug + '/' + Api.usersFilterFor(data.slug)));
|
|
|
|
});
|
|
|
|
|
|
|
|
$.when.apply($, requests).then(function() {
|
|
|
|
for(let i = 0; i < arguments.length; i++) {
|
|
|
|
items.push({
|
|
|
|
category: arguments[i][0].category,
|
|
|
|
items: arguments[i][0].items
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
self.setState({
|
|
|
|
items: items
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Home;
|