fixed bug with amount not updating / solved double dispatch problem with cartAction.load / removed all console.log calls - it became too chatty / add them as needed

This commit is contained in:
Senad Uka
2015-05-14 06:21:49 +02:00
parent 49dd10acbc
commit 6453b1b241
22 changed files with 73 additions and 104 deletions

View File

@@ -91,7 +91,7 @@ var BySection = React.createClass({
SectionActions.loadSectionDetails(sectionId);
},
componentDidMount: function() {
console.log('mounting....');
var sectionId = this.getParams().id;
ItemActions.loadBestSellingItemsForSection(sectionId);
SectionActions.loadSectionDetails(sectionId);
@@ -112,7 +112,7 @@ var BySection = React.createClass({
},
_onChange: function() {
if(this.isMounted()) {
console.log('items store changed! by section');
this.setState({items: ItemStore.getBestSellingForSection()});
}
}

View File

@@ -35,12 +35,15 @@ var AddToCart = React.createClass({
// Add change listeners to stores
componentDidMount: function() {
CartStore.addChangeListener(this._onChange);
CartActions.load();
if(!CartStore.dataStartedLoading()) {
CartActions.load();
};
},
getInitialState: function() {
var itemInCart = CartStore.getStateFor(this.props.itemId);
var itemInCart = CartStore.getStateFor(this.props.item.get('id'));
return {
item: itemInCart,
count: 0
@@ -50,13 +53,13 @@ var AddToCart = React.createClass({
_onChange: function () {
if (this.isMounted()) {
var item = CartStore.getStateFor(this.props.itemId);
var item = CartStore.getStateFor(this.props.item.get('id'));
this.setState({ item: item, count: 0 });
}
},
_onIncreaseClick: function () {
//CartActions.addItem(this.props.itemId);
if (this.state.count < Globals.MaxNumberOfItemsToBeAdded ) {
this.state.count = this.state.count + 1;
this.setState(this.state);
@@ -64,7 +67,7 @@ var AddToCart = React.createClass({
},
_onDecreaseClick: function () {
// CartActions.takeItemOut(this.props.itemId);
if (this.state.count > 0) {
this.state.count = this.state.count - 1;
this.setState(this.state);
@@ -72,7 +75,7 @@ var AddToCart = React.createClass({
},
_addToCartClick: function () {
CartActions.setItemCount(this.props.itemId, this.state.count);
CartActions.setItemCount(this.props.item, this.state.count);
},
componentWillUnmount: function () {

View File

@@ -40,7 +40,9 @@ var CartIcon = React.createClass({
// Add change listeners to stores
componentDidMount: function() {
CartStore.addChangeListener(this._onChange);
CartActions.load();
if(!CartStore.dataStartedLoading()) {
CartActions.load();
};
},
@@ -51,6 +53,7 @@ var CartIcon = React.createClass({
_onChange: function () {
if (this.isMounted()) {
this.setState(CartStore.getWholeCartState());
}
},

View File

@@ -27,7 +27,8 @@ var CartPage = React.createClass({
<div key={i.get('id')} className="row cart-items">
<div className="col-md-3"><SingleItem item={i} hidePrice={true}/> </div>
<div className="col-md-2"> { Globals.FormatCurrency(price) }</div>
<div className="col-md-3"> <AddToCart itemId={i.get('id')} /> </div>
<div className="col-md-3">
42 </div>
<div className="col-md-2"> { Globals.FormatCurrency(count * price) }</div>
</div>
@@ -65,7 +66,7 @@ var CartPage = React.createClass({
};
console.log("length :" , this.state.items.length);
return (

View File

@@ -8,42 +8,25 @@ var Router = require('react-router');
var CartTotal = React.createClass({
render: function() {
render: function() {
var counts = this.props.itemCounts;
var total = 0;
this.props.items.map(function (i) {
var count = counts[i.get('id')].get('count');
var price = i.get('list_price');
var items = this.props.items.models;
for (var i = 0; i < items.length; i++) {
var item = items[i];
var count = counts[item.get('id')].get('count');
var price = item.get('list_price');
total += (price * count)
return total;
};
});
var deliveryCosts = this.props.deliveryCosts.get('delivery_price');
if (!this.props.justMerchandise) {
return (
<div className="col-md-3 cart-total">
<div>
Roba: {Globals.FormatCurrency(total)}
</div>
<div>
Dostava: {Globals.FormatCurrency(deliveryCosts)}
</div>
<div>
Ukupno: {Globals.FormatCurrency(total + (+deliveryCosts))}
</div>
</div>
);
}
else {
return ( <span>{Globals.FormatCurrency(total)}</span>);
}
return ( <span>{Globals.FormatCurrency(total)}</span>);
}

View File

@@ -25,10 +25,10 @@ var ItemWithDetailsPage = React.createClass({
<div className='item_name'> {this.state.item.get('name')}</div>
<div>
<div className='item_price'> {this.state.item.get('list_price')} KM</div>
<div>Količina</div>
<div> <AddToCart itemId={this.state.item.get('id')} /></div>
<div> <AddToCart item={this.state.item} /></div>
<div> {this.state.item.get('description')}</div>
</div>

View File

@@ -44,7 +44,7 @@ var SingleItem = React.createClass({
itemClick: function(e) {
NavigationActions.goToItemDetails(this.props.item);
console.log(this.props.item)
}
});