Skip to content

Commit

Permalink
feat(usermenu): connect to store and get cart state
Browse files Browse the repository at this point in the history
display cart's quantity next to cart icon
  • Loading branch information
aneurysmjs committed Aug 20, 2019
1 parent 3738ea9 commit d533941
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app/components/core/UserMenu/UserMenu.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// @flow strict
import React, { useState } from 'react';
// $FlowFixMe
import { useSelector } from 'react-redux';

import Icon from '@/components/base/Icon/Icon';
import { useLazy } from '@/hooks/useLazy';
import { getCart } from '@/store/reducers/cart';

import type { CartType } from '@/store/types/CartType';

import './UserMenu.scss';

const UserMenu = () => {
const [open, setOpen] = useState(false);
const cart: CartType = useSelector(getCart);

const handleOpen = () => setOpen(!open);

Expand All @@ -32,6 +38,7 @@ const UserMenu = () => {
</Sidebar>)
: null}
<span
className="user-menu__cart-icon"
tabIndex="-1"
role="button"
onKeyPress={() => {}}
Expand All @@ -41,6 +48,9 @@ const UserMenu = () => {
size="20"
path="icons/cart"
/>
<span className="user-menu__cart-quantity">
({ cart.quantity })
</span>
</span>
</div>
);
Expand Down
9 changes: 9 additions & 0 deletions src/app/components/core/UserMenu/UserMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
align-items: center;
display: flex;
padding: 0 px-to-rem(16);

@include element(cart-icon) {
align-items: center;
display: flex;
}

@include element(cart-quantity) {
margin-left: px-to-rem(5);
}
}

0 comments on commit d533941

Please sign in to comment.