<commit_before>import IconButton from 'material-ui/IconButton';
import { white } from 'material-ui/styles/colors';
import ActionShoppingCart from 'material-ui/svg-icons/action/shopping-cart';
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { createToggleShoppingCartDrawer } from '../actions';

const ShoppingCartMenu = ({
  toggleShoppingCartDrawer,
}) => (
  <IconButton onClick={toggleShoppingCartDrawer}>
    <ActionShoppingCart color={white} />
  </IconButton>
);

ShoppingCartMenu.propTypes = {
  toggleShoppingCartDrawer: PropTypes.func.isRequired,
};

export default connect(
  () => ({}),
  dispatch => ({
    toggleShoppingCartDrawer() {
      dispatch(createToggleShoppingCartDrawer());
    },
  }),<commit_msg>add badge with shoppingcart items count<commit_after>import Badge from 'material-ui/Badge';
import { white } from 'material-ui/styles/colors';
import ActionShoppingCart from 'material-ui/svg-icons/action/shopping-cart';
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { createToggleShoppingCartDrawer } from '../actions';
import { ShoppingCartItemsPropType } from '../propTypes';

const ShoppingCartMenu = ({
  toggleShoppingCartDrawer,
  shoppingCartItems,
}) => {
  const itemCount = shoppingCartItems.reduce((sum, item) => sum + item.amount, 0);

  return (
    <Badge
      badgeContent={itemCount}
      onClick={toggleShoppingCartDrawer}
      secondary
      style={{
        padding: '12px',
        cursor: 'pointer',
      }}
      badgeStyle={{
        top: '-2px',
        right: '-2px',
        visibility: itemCount === 0 ? 'hidden' : 'visible',
      }}
    >
      <ActionShoppingCart color={white} />
    </Badge>
  );
};

ShoppingCartMenu.propTypes = {
  shoppingCartItems: ShoppingCartItemsPropType.isRequired,
  toggleShoppingCartDrawer: PropTypes.func.isRequired,
};

export default connect(
  state => ({
    shoppingCartItems: state.shoppingCart.items,
  }),
  dispatch => ({
    toggleShoppingCartDrawer() {
      dispatch(createToggleShoppingCartDrawer());
    },
  }),
{'fraction_non_alphanumeric': 0.13376987839101964, 'fraction_numerical': 0.002806361085126286, 'mean_word_length': 4.080760095011876, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3303907', 'n_tokens_mistral': 640, 'n_tokens_neox': 650, 'n_words': 130}