suggested articles / email is now sent
This commit is contained in:
50
front-ui/app/components/items/randomItems.js
Normal file
50
front-ui/app/components/items/randomItems.js
Normal file
@@ -0,0 +1,50 @@
|
||||
var React = require('react');
|
||||
var ItemList = require('./itemList');
|
||||
var ItemStore = require('../../stores/itemStore.js');
|
||||
var ItemActions = require('../../actions/itemActions.js');
|
||||
var ItemCollection = require('../../models/itemCollection');
|
||||
|
||||
var RandomItems = React.createClass({
|
||||
|
||||
render: function() {
|
||||
return (
|
||||
<ItemList items={this.state.items} />
|
||||
);
|
||||
},
|
||||
|
||||
// Add change listeners to stores
|
||||
componentDidMount: function() {
|
||||
ItemActions.loadFrontPageItems();
|
||||
ItemStore.addChangeListener(this._onChange);
|
||||
},
|
||||
|
||||
componentWillUnmount: function () {
|
||||
ItemStore.removeChangeListener(this._onChange);
|
||||
},
|
||||
|
||||
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
items: this.getRandomItems()
|
||||
}
|
||||
},
|
||||
|
||||
getRandomItems: function() {
|
||||
var NUMBER_OF_SUGGESTED_ITEMS = 8;
|
||||
var allItems = ItemStore.getItems();
|
||||
var randomIndexStart = Math.floor(Math.random() * ((allItems.models.length - NUMBER_OF_SUGGESTED_ITEMS + 1)));
|
||||
allItems.models = allItems.models.slice(randomIndexStart, randomIndexStart + NUMBER_OF_SUGGESTED_ITEMS);
|
||||
return allItems;
|
||||
},
|
||||
|
||||
|
||||
_onChange: function () {
|
||||
|
||||
this.setState({
|
||||
items: this.getRandomItems()
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = RandomItems;
|
||||
Reference in New Issue
Block a user