From 6fc5969fe6d991303b0115839385a6d9149f73ac Mon Sep 17 00:00:00 2001 From: Edin Dazdarevic Date: Wed, 4 Feb 2015 06:51:49 +0100 Subject: [PATCH] by category page --- front-ui/app/actions/itemActions.js | 6 ++ .../app/components/browsing/byCategory.js | 64 ++++++++++++++++--- front-ui/app/components/browsing/bySection.js | 9 ++- front-ui/app/constants/itemConstants.js | 3 +- front-ui/app/models/category.js | 12 ++++ front-ui/app/models/categoryCollection.js | 0 front-ui/app/stores/itemStore.js | 22 ++++++- 7 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 front-ui/app/models/category.js create mode 100644 front-ui/app/models/categoryCollection.js diff --git a/front-ui/app/actions/itemActions.js b/front-ui/app/actions/itemActions.js index 6e823af..e24752d 100644 --- a/front-ui/app/actions/itemActions.js +++ b/front-ui/app/actions/itemActions.js @@ -4,6 +4,12 @@ var ItemConstants = require('../constants/itemConstants'); // Define action methods var ItemActions = { + loadByCategory: function(categoryId) { + AppDispatcher.handleAction({ + actionType: ItemConstants.LOAD_BY_CATEGORY, + categoryId : categoryId + }); + }, loadFrontPageItems: function() { AppDispatcher.handleAction({ diff --git a/front-ui/app/components/browsing/byCategory.js b/front-ui/app/components/browsing/byCategory.js index 9dc54c4..34c93df 100644 --- a/front-ui/app/components/browsing/byCategory.js +++ b/front-ui/app/components/browsing/byCategory.js @@ -1,13 +1,61 @@ -var React = require('react'); +var React = require('react'), + Router = require('react-router'), + Category = require('../../models/category'), + ItemCollection = require('../../models/itemCollection'), + ItemActions = require('../../actions/itemActions.js'), + ItemStore = require('../../stores/itemStore'), + NavigationStore = require('../../stores/navigationStore'), + ItemList = require('../items/itemList'), + NavigationActions = require('../../actions/navigationActions'); var ByCategory = React.createClass({ - render: function() { - return ( -
-

Browse products by category

-
- ); - } + mixins: [Router.State], + getInitialState: function() { + var category = new Category(); + var items = new ItemCollection(); + return { + category: category, + items: items + }; + }, + render: function() { + return ( +
+
+ Here goes section for refining search, by section +
+ +
+ +

Browse products by category

+ Number of items in this category: {this.state.items.length} + +
+
+ ); + }, + componentWillReceiveProps: function() { + var categoryId = this.getParams().id; + ItemActions.loadByCategory(categoryId); + // TODO: load category details + }, + componentDidMount: function() { + var categoryId = this.getParams().id; + ItemActions.loadByCategory(categoryId); + + ItemStore.addChangeListener(this._onChange); + }, + componentWillUnmount: function() { + ItemStore.removeChangeListener(this._onChange); + }, + _onChange: function() { + if(this.isMounted()) { + this.setState({ + items: ItemStore.getItemsForCategory() + }); + } + } + }); module.exports = ByCategory; diff --git a/front-ui/app/components/browsing/bySection.js b/front-ui/app/components/browsing/bySection.js index edd0aac..5196ee9 100644 --- a/front-ui/app/components/browsing/bySection.js +++ b/front-ui/app/components/browsing/bySection.js @@ -37,8 +37,11 @@ var BySection = React.createClass({ return (
+ + -
{category.name}
+
{category.name}
+