diff --git a/front-ui/README.md b/front-ui/README.md index e1a4838..609e60a 100644 --- a/front-ui/README.md +++ b/front-ui/README.md @@ -1,6 +1,6 @@ # Ribica front office -Front end shop-a (javascript) +Front end of the shop (javascript) All the code is in the ``app`` folder. This structure will evolve over time. @@ -12,3 +12,11 @@ All the code is in the ``app`` folder. This structure will evolve over time. Visit ``http://localhost:3001/index.html`` +# Few flux guidelines + +* State is always stored in the store and only synced with component as near to the top as it makes locigal sense +* Stores are read only - they don't allow state changes directly but implement listeners that change state when dispacher tells them +* Stores inform components about changes in state through change event +* Stores fetch models - components never do this but get them from the props in most cases, or from the state in some cases (top components) +* Navigation goes through navigation store and only navigation store accesses the router + diff --git a/front-ui/app/actions/navigationActions.js b/front-ui/app/actions/navigationActions.js index f5b5835..14c583d 100644 --- a/front-ui/app/actions/navigationActions.js +++ b/front-ui/app/actions/navigationActions.js @@ -11,7 +11,32 @@ var NavigationActions = { actionType: NavigationConstants.CHANGE_URL, url: '/artikal/' + item.get('id') +'/' + item.get('name') }); - } + }, + + goToSection: function(section) { + console.log("Going to item details"); + AppDispatcher.handleAction({ + actionType: NavigationConstants.CHANGE_URL, + url: '/sekcija/'+ section.get('id') + '/' + section.get('name') + }); + }, + + goToCategory: function(category,section) { + console.log("Going to item details"); + AppDispatcher.handleAction({ + actionType: NavigationConstants.CHANGE_URL, + url: '/sekcija/' + section.get('name') +'/kategorija/'+ category.id + '/' + category.name + }); + }, + + goToSubCategory: function(subCategory) { + // TODO: implement when ready + AppDispatcher.handleAction({ + actionType: NavigationConstants.CHANGE_URL, + url: '/' + }); + }, + }; diff --git a/front-ui/app/actions/sectionActions.js b/front-ui/app/actions/sectionActions.js new file mode 100644 index 0000000..1624a72 --- /dev/null +++ b/front-ui/app/actions/sectionActions.js @@ -0,0 +1,29 @@ +var AppDispatcher = require('../dispatcher/appDispatcher'); +var SectionConstants = require('../constants/sectionConstants'); + +// Define action methods +var SectionActions = { + + loadSections: function() { + AppDispatcher.handleAction({ + actionType: SectionConstants.LOAD_SECTIONS + }) + }, + + + setSectionHover: function(section) { + AppDispatcher.handleAction({ + actionType: SectionConstants.SET_SECTION_HOVER, + section: section + }) + }, + + unsetSectionHover: function() { + AppDispatcher.handleAction({ + actionType: SectionConstants.UNSET_SECTION_HOVER + }) + } + +}; + +module.exports = SectionActions; \ No newline at end of file diff --git a/front-ui/app/components/shared/sectionsListComponent.js b/front-ui/app/components/shared/sectionsListComponent.js index 6dfafb3..588ecf5 100644 --- a/front-ui/app/components/shared/sectionsListComponent.js +++ b/front-ui/app/components/shared/sectionsListComponent.js @@ -1,65 +1,49 @@ var React = require('react'), SectionCollection = require('../../models/sectionCollection'), Section = require('../../models/section'), - Backbone = require('backbone'); - -var Navigation = require('react-router').Navigation; + Backbone = require('backbone'), + NavigationStore = require('../../stores/navigationStore'), + SectionStore = require('../../stores/sectionStore'), + SectionActions = require('../../actions/sectionActions'), + NavigationActions = require('../../actions/navigationActions'); Backbone.$ = $; var SectionsListComponent = React.createClass({ - mixins : [Navigation], - getInitialState: function() { - return { - sections : [], - hoveredSection : '' - }; + + _onChange: function () { + if (this.isMounted()) { + this.setState(SectionStore.getState()); + } }, + + getInitialState: function() { + return SectionStore.getState(); + }, + componentDidMount: function() { - var sections = new SectionCollection(); - sections.fetch({success: function() { - console.log('Loaded sections:' , sections); - if(this.isMounted()) { - this.setState({ - sections: sections.models - }); - } - - - }.bind(this)}); + SectionStore.addChangeListener(this._onChange); + SectionActions.loadSections(); }, onMouseOver: function(section) { - //console.log('mouse over!', section); - - this.setState({ - hoveredSection: section.get('id') - }); + SectionActions.setSectionHover(section); + }, onMouseOut: function() { - this.setState({ - hoveredSection : '' - }); + SectionActions.unsetSectionHover(); }, onSectionClick: function(section) { - //alert('clicked on section:'+ section.get('name')); - this.transitionTo('/sekcija/'+ section.get('id') + '/' + section.get('name')); - this.setState({ - hoveredSection : '' - }); - + NavigationActions.goToSection(section); return false; }, onCategoryClick: function(category, section) { - - this.transitionTo('/sekcija/' + section.get('name') +'/kategorija/'+ category.id + '/' + category.name); - this.setState({ - hoveredSection: '' - }); - console.log('category', category.id); + NavigationActions.goToCategory(category, section); return false; }, onSubcategoryClick: function(subcategory) { - + // implement in navigation actions + // and call + // when ready return false; }, render: function() { @@ -82,7 +66,7 @@ var SectionsListComponent = React.createClass({
-