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:
@@ -10,24 +10,10 @@ var CartActions = {
|
||||
});
|
||||
},
|
||||
|
||||
addItem: function(itemId) {
|
||||
AppDispatcher.handleAction({
|
||||
actionType: CartConstants.ADD_ITEM,
|
||||
itemId: itemId
|
||||
});
|
||||
},
|
||||
|
||||
takeItemOut: function(itemId) {
|
||||
AppDispatcher.handleAction({
|
||||
actionType: CartConstants.TAKE_ITEM_OUT,
|
||||
itemId: itemId
|
||||
});
|
||||
},
|
||||
|
||||
setItemCount: function(itemId, count) {
|
||||
setItemCount: function(item, count) {
|
||||
AppDispatcher.handleAction({
|
||||
actionType: CartConstants.SET_ITEM_COUNT,
|
||||
itemId: itemId,
|
||||
item: item,
|
||||
count: count
|
||||
});
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ var NavigationConstants = require('../constants/navigationConstants');
|
||||
var NavigationActions = {
|
||||
// select item
|
||||
goToItemDetails: function(item) {
|
||||
console.log("Going to item details");
|
||||
|
||||
AppDispatcher.handleAction({
|
||||
actionType: NavigationConstants.CHANGE_URL,
|
||||
url: '/artikal/' + item.get('id') +'/' + item.get('name')
|
||||
@@ -13,7 +13,6 @@ var NavigationActions = {
|
||||
},
|
||||
|
||||
goToSection: function(section) {
|
||||
console.log("Going to item details");
|
||||
AppDispatcher.handleAction({
|
||||
actionType: NavigationConstants.CHANGE_URL,
|
||||
url: '/sekcija/'+ section.get('id') + '/' + section.get('name')
|
||||
|
||||
@@ -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()});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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 (
|
||||
|
||||
|
||||
@@ -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>);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ var SingleItem = React.createClass({
|
||||
|
||||
itemClick: function(e) {
|
||||
NavigationActions.goToItemDetails(this.props.item);
|
||||
console.log(this.props.item)
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ var keyMirror = require('react/lib/keyMirror');
|
||||
// Define action constants
|
||||
module.exports = keyMirror({
|
||||
LOAD_CART_CONTENTS: null,
|
||||
ADD_ITEM: null,
|
||||
TAKE_ITEM_OUT: null ,
|
||||
CART_DATA_LOADED: null,
|
||||
SAVE_CART_STATE_FOR_ITEM: null,
|
||||
CHANGE_DELIVERY_DESTINATION_PROPERTY: null,
|
||||
|
||||
@@ -10,7 +10,7 @@ AppDispatcher.handleAction = function(action) {
|
||||
action: action
|
||||
});
|
||||
|
||||
console.log("Dispatching:", action);
|
||||
|
||||
}
|
||||
|
||||
module.exports = AppDispatcher;
|
||||
@@ -106,7 +106,7 @@ var BySubCategoryStore = _.extend({}, EventEmitter.prototype, {
|
||||
},
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("Emmiting BySubCategory change!");
|
||||
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
|
||||
@@ -24,8 +24,12 @@ var _deliveryCosts = new Place({
|
||||
postalCode: _deliveryDestination.get('place')
|
||||
})
|
||||
|
||||
var _cartDataLoadCalled = false;
|
||||
|
||||
|
||||
var loadCart = function() {
|
||||
|
||||
states = {};
|
||||
_itemsInCart.fetch({
|
||||
success: function() {
|
||||
states = {}
|
||||
@@ -50,8 +54,10 @@ var loadCart = function() {
|
||||
CartActions.dataLoaded();
|
||||
}
|
||||
});
|
||||
|
||||
_cartDataLoadCalled = true;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
var fetchPlace = function() {
|
||||
@@ -71,22 +77,12 @@ var saveCartStateForItem = function(itemId) {
|
||||
var item = CartStore.getStateFor(itemId);
|
||||
item.save({
|
||||
success: function() {
|
||||
CartActions.dataLoaded();
|
||||
loadCart();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var addItem = function(itemId) {
|
||||
|
||||
var state = states[itemId] || new ItemInCart({
|
||||
item_id: itemId,
|
||||
count: 0
|
||||
})
|
||||
state.set('count', state.get('count') + 1);
|
||||
states[itemId] = state;
|
||||
saveCartStateForItem(itemId);
|
||||
|
||||
};
|
||||
/* need it for delete - will delete it later
|
||||
|
||||
var takeItemOut = function(itemId) {
|
||||
|
||||
@@ -101,15 +97,20 @@ var takeItemOut = function(itemId) {
|
||||
saveCartStateForItem(itemId);
|
||||
};
|
||||
|
||||
var setItemCount = function(itemId, count) {
|
||||
*/
|
||||
|
||||
var setItemCount = function(item, count) {
|
||||
|
||||
var itemId = item.get('id');
|
||||
var state = states[itemId] || new ItemInCart({
|
||||
item_id: itemId,
|
||||
count: 0
|
||||
})
|
||||
console.log("Old state", state.get('count'));
|
||||
|
||||
_itemsForDisplay.add(item);
|
||||
|
||||
state.set('count', state.get('count') + count);
|
||||
console.log("New state", state.get('count'));
|
||||
|
||||
states[itemId] = state;
|
||||
saveCartStateForItem(itemId);
|
||||
}
|
||||
@@ -125,7 +126,7 @@ var changeDeliveryDestinationProperty = function(property, value) {
|
||||
|
||||
|
||||
var confirmOrder = function() {
|
||||
console.log("confirming");
|
||||
|
||||
var oc = new OrderConfirmation({
|
||||
hamo: 'meho'
|
||||
});
|
||||
@@ -133,7 +134,7 @@ var confirmOrder = function() {
|
||||
b: 'b'
|
||||
}, {
|
||||
success: function() {
|
||||
console.log("done");
|
||||
|
||||
NavigationActions.goToThankYou();
|
||||
loadCart();
|
||||
}
|
||||
@@ -142,10 +143,9 @@ var confirmOrder = function() {
|
||||
|
||||
|
||||
var saveDeliveryDestination = function() {
|
||||
console.log("saving delivery destination");
|
||||
_deliveryDestination.save(null, {
|
||||
success: function() {
|
||||
console.log("saved delivery destination");
|
||||
|
||||
confirmOrder();
|
||||
}
|
||||
})
|
||||
@@ -197,6 +197,10 @@ var isDeliveryDestinationValid = function() {
|
||||
// Extend CartStore with EventEmitter to add eventing capabilities
|
||||
var CartStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
dataStartedLoading: function() {
|
||||
return _cartDataLoadCalled;
|
||||
},
|
||||
|
||||
getStateFor: function(itemId) {
|
||||
|
||||
var state = states[itemId] || new ItemInCart({
|
||||
@@ -234,7 +238,6 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("Emitting cart change!");
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
@@ -288,7 +291,7 @@ AppDispatcher.register(function(payload) {
|
||||
saveDeliveryDestination();
|
||||
break;
|
||||
case CartConstants.SET_ITEM_COUNT:
|
||||
setItemCount(action.itemId, action.count);
|
||||
setItemCount(action.item, action.count);
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
|
||||
@@ -45,7 +45,7 @@ var CategoryStore = _.extend({}, EventEmitter.prototype, {
|
||||
},
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("Emmiting Section change!");
|
||||
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ var InitializationStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("InitializationStore change!");
|
||||
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ var getItemIdFromUrl = function() {
|
||||
var url = document.URL;
|
||||
var itemIdRegex = /artikal\/(\d+)\//g;
|
||||
var match = itemIdRegex.exec(url);
|
||||
console.log(match);
|
||||
|
||||
return match[1];
|
||||
};
|
||||
|
||||
@@ -95,7 +95,6 @@ var ItemWithDetailsStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("Emitting change!");
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ var getItemIdFromUrl = function() {
|
||||
var url = document.URL;
|
||||
var itemIdRegex = /artikal\/(\d+)\//g;
|
||||
var match = itemIdRegex.exec(url);
|
||||
console.log(match);
|
||||
|
||||
return match[1];
|
||||
};
|
||||
|
||||
@@ -80,7 +80,7 @@ var fetchItemsByCategory = function(categoryId, offset, limit, query) {
|
||||
};
|
||||
|
||||
var fetchBestSellingItemsForSection = function(sectionId) {
|
||||
console.log('getting section', sectionId);
|
||||
|
||||
var items = _bestSellingForSection;
|
||||
items.setClassificationType(1);
|
||||
items.setClassificationId(sectionId);
|
||||
@@ -96,7 +96,7 @@ var fetchBestSellingItemsForSection = function(sectionId) {
|
||||
|
||||
|
||||
var fetchBestSellingItemsForGroup = function(groupId) {
|
||||
console.log('getting group', groupId);
|
||||
|
||||
var items = _bestSellingForGroup;
|
||||
items.setClassificationType(4);
|
||||
items.setClassificationId(groupId);
|
||||
@@ -138,7 +138,7 @@ var ItemStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("Emitting change!");
|
||||
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ var MenuItemStore = _.extend({}, EventEmitter.prototype, {
|
||||
},
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("Emmiting MenuItemStore change!");
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ var _ = require('underscore');
|
||||
|
||||
|
||||
var getGroupIdFromUrl = function() {
|
||||
console.log("yeee" , match);
|
||||
// ugly but it seems to me that
|
||||
// router does not want to expose its
|
||||
// state (for phylosophical reasons)
|
||||
@@ -31,7 +30,6 @@ var NavigationStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("NavigationStore change!");
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ var SearchStore = _.extend({}, EventEmitter.prototype, {
|
||||
},
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("SearchStore change!");
|
||||
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ var loadSectionDetails = function(sectionId) {
|
||||
section.fetch({
|
||||
success: function() {
|
||||
_sectionDetails = section;
|
||||
console.log('section details', _sectionDetails);
|
||||
|
||||
SectionStore.emitChange();
|
||||
}
|
||||
});
|
||||
@@ -53,7 +53,7 @@ var SectionStore = _.extend({}, EventEmitter.prototype, {
|
||||
},
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("Emmiting Section change!");
|
||||
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ var handleRegistrationFailure = function(error) {
|
||||
error: error
|
||||
};
|
||||
|
||||
|
||||
console.log('ERROR JE: ', error);
|
||||
};
|
||||
|
||||
var handleLoginSuccess = function(user) {
|
||||
@@ -92,7 +90,6 @@ var UserStore = _.extend({}, EventEmitter.prototype, {
|
||||
},
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("Emmiting Section change!");
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user