loading category details on category browsing page

This commit is contained in:
Edin Dazdarevic
2015-02-07 12:30:10 +01:00
parent a642cb55eb
commit 0bb6bb5a49
4 changed files with 125 additions and 3 deletions

View File

@@ -3,6 +3,8 @@ var React = require('react'),
Category = require('../../models/category'),
ItemCollection = require('../../models/itemCollection'),
ItemActions = require('../../actions/itemActions.js'),
CategoryActions = require('../../actions/categoryActions.js'),
CategoryStore = require('../../stores/categoryStore'),
ItemStore = require('../../stores/itemStore'),
NavigationStore = require('../../stores/navigationStore'),
ItemList = require('../items/itemList'),
@@ -27,7 +29,7 @@ var ByCategory = React.createClass({
<div className='col-md-10'>
<h3> Browse products by category</h3>
<h3> Browse products by category : {this.state.category.get('name')}</h3>
Number of items in this category: {this.state.items.length}
<ItemList items={this.state.items} />
</div>
@@ -37,21 +39,25 @@ var ByCategory = React.createClass({
componentWillReceiveProps: function() {
var categoryId = this.getParams().id;
ItemActions.loadByCategory(categoryId);
// TODO: load category details
CategoryActions.loadCategoryDetails(categoryId);
},
componentDidMount: function() {
var categoryId = this.getParams().id;
ItemActions.loadByCategory(categoryId);
CategoryActions.loadCategoryDetails(categoryId);
ItemStore.addChangeListener(this._onChange);
CategoryStore.addChangeListener(this._onChange);
},
componentWillUnmount: function() {
ItemStore.removeChangeListener(this._onChange);
CategoryStore.removeChangeListener(this._onChange);
},
_onChange: function() {
if(this.isMounted()) {
this.setState({
items: ItemStore.getItemsForCategory()
items: ItemStore.getItemsForCategory(),
category: CategoryStore.getCategoryDetails()
});
}
}