File tree Expand file tree Collapse file tree 7 files changed +57
-9
lines changed Expand file tree Collapse file tree 7 files changed +57
-9
lines changed Original file line number Diff line number Diff line change 11.cart-dropdown {
22 position : absolute ;
33 width : 240px ;
4- height : 340 px ;
4+ height : auto ;
55 display : flex ;
66 flex-direction : column ;
77 padding : 20px ;
Original file line number Diff line number Diff line change 11import React from 'react'
2+ import { connect } from 'react-redux'
3+
4+ import { toggleCartHidden } from '../../redux/cart/cart.actions'
5+
26import './cart-icon.styles.scss'
37import { ReactComponent as ShoppingIcon } from '../../assets/shopping-bag.svg'
4- export default function CartIcon ( ) {
8+
9+ function CartIcon ( { toggleCartHidden } ) {
510 return (
6- < div className = "cart-icon" >
11+ < div className = "cart-icon" onClick = { toggleCartHidden } >
712 < ShoppingIcon className = "shopping-icon" />
813 < span className = "item-count" > 0</ span >
914 </ div >
1015 )
1116}
17+
18+ const mapDispatchToProps = dispatch => ( {
19+ toggleCartHidden : ( ) => dispatch ( toggleCartHidden ( ) )
20+ } )
21+
22+ export default connect ( null , mapDispatchToProps ) ( CartIcon )
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { Link } from 'react-router-dom'
66import { auth } from '../../firebase/firebase.utils'
77import CartIcon from '../cart-icon/Cart-icon'
88import CartDropdown from '../cart-dropdown/cart-dropdown.component'
9- function Header ( { currentUser } ) {
9+ function Header ( { currentUser, hidden } ) {
1010 return (
1111 < div className = "header" >
1212 < Link to = "/" className = "logo-container" >
@@ -31,13 +31,17 @@ function Header({ currentUser }) {
3131 }
3232 < CartIcon />
3333 </ div >
34- < CartDropdown />
34+ {
35+ hidden ? null : < CartDropdown />
36+ }
37+
3538 </ div >
3639 )
3740}
3841
39- const mapStatetoProps = state => ( {
40- currentUser : state . user . currentUser
42+ const mapStatetoProps = ( { user : { currentUser } , cart : { hidden } } ) => ( {
43+ currentUser,
44+ hidden
4145} )
4246
4347export default connect ( mapStatetoProps ) ( Header )
Original file line number Diff line number Diff line change 1+ import CartActionTypes from './cart.types'
2+
3+ export const toggleCartHidden = ( ) => ( {
4+ type : CartActionTypes . TOGGLE_CART_HIDDEN
5+ } )
Original file line number Diff line number Diff line change 1+ import CartActionTypes from './cart.types'
2+
3+
4+ const INITIAL_STATE = {
5+ hidden : true
6+ }
7+
8+
9+ const cartReducer = ( state = INITIAL_STATE , action ) => {
10+
11+ switch ( action . type ) {
12+ case CartActionTypes . TOGGLE_CART_HIDDEN :
13+ return {
14+ ...state ,
15+ hidden : ! state . hidden
16+ }
17+ default :
18+ return state
19+ }
20+ }
21+
22+ export default cartReducer
Original file line number Diff line number Diff line change 1+ const CartActionTypes = {
2+ TOGGLE_CART_HIDDEN : 'TOGGLE_CART_HIDDEN'
3+ }
4+
5+ export default CartActionTypes
Original file line number Diff line number Diff line change 11import { combineReducers } from 'redux'
22import userReducer from './user/user.reducer'
3-
3+ import cartReducer from './cart/cart.reducer'
44
55export default combineReducers ( {
6- user : userReducer
6+ user : userReducer ,
7+ cart : cartReducer
78} )
You can’t perform that action at this time.
0 commit comments