1
0
mirror of https://github.com/devfake/flox.git synced 2024-11-15 14:42:31 +01:00
flox/client/app/sites/home.js
2016-02-23 09:11:31 +01:00

57 lines
1.1 KiB
JavaScript

import React from 'react';
import Box from '../partials/box';
import Api from '../api';
class Home extends React.Component {
constructor() {
super();
this.loadHomeItems();
this.state = {
items: []
};
}
render() {
let boxes = this.state.items.map((value, key) => {
return <Box items={value.items} category={value.category} key={key} type="home" currentLoaded="5" />
});
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;