created cart icon with number of items notification - it's still buggy
This commit is contained in:
49
front-ui/app/components/cart/cartIcon.js
Normal file
49
front-ui/app/components/cart/cartIcon.js
Normal file
@@ -0,0 +1,49 @@
|
||||
var React = require('react');
|
||||
var CartStore = require('../../stores/cartStore.js');
|
||||
var CartActions = require('../../actions/cartActions.js');
|
||||
|
||||
|
||||
|
||||
var cartStyle = {
|
||||
fontSize: '50px'
|
||||
};
|
||||
|
||||
var CartIcon = React.createClass({
|
||||
|
||||
render: function() {
|
||||
|
||||
var textNotificationStyle = (this.state.count > 0) ? { display: 'inline-block'} : { display: 'none'} ;
|
||||
|
||||
return (
|
||||
<div className="shopping-cart-icon">
|
||||
<i style={cartStyle} className="fa fa-shopping-cart"></i>
|
||||
<div style={textNotificationStyle} className="shopping-cart-notification-text">{this.state.count}</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
// Add change listeners to stores
|
||||
componentDidMount: function() {
|
||||
CartStore.addChangeListener(this._onChange);
|
||||
CartActions.load();
|
||||
},
|
||||
|
||||
|
||||
getInitialState: function() {
|
||||
var cartState = CartStore.getWholeCartState();
|
||||
return cartState;
|
||||
},
|
||||
|
||||
_onChange: function () {
|
||||
if (this.isMounted()) {
|
||||
this.setState(CartStore.getWholeCartState());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
module.exports = CartIcon;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user