-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7567f70
commit cd10598
Showing
85 changed files
with
1,604 additions
and
1,315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
|
||
test('renders learn react link', () => { | ||
render(<App />); | ||
const linkElement = screen.getByText(/learn react/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<App />, div); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,43 @@ | ||
import React from "react"; | ||
import { connect } from "react-redux"; | ||
import { createStructuredSelector } from "reselect"; | ||
import { withRouter } from "react-router-dom"; | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { createStructuredSelector } from 'reselect'; | ||
import { withRouter } from 'react-router-dom'; | ||
|
||
import CustomButton from "../custom-button/custom-button.component"; | ||
import CartItem from "../cart-item/cart-item.component"; | ||
import { selectCartItems } from "../../redux/cart/cart.selectors"; | ||
import { toggleCartHidden } from "../../redux/cart/cart.actions"; | ||
import CartItem from '../cart-item/cart-item.component'; | ||
import { selectCartItems } from '../../redux/cart/cart.selectors'; | ||
import { toggleCartHidden } from '../../redux/cart/cart.actions.js'; | ||
|
||
import "./cart-dropdown.styles.scss"; | ||
import { | ||
CartDropdownContainer, | ||
CartDropdownButton, | ||
EmptyMessageContainer, | ||
CartItemsContainer | ||
} from './cart-dropdown.styles'; | ||
|
||
const CartDropdown = ({ cartItems, history, dispatch }) => { | ||
return ( | ||
<div className="cart-dropdown"> | ||
const CartDropdown = ({ cartItems, history, dispatch }) => ( | ||
<CartDropdownContainer> | ||
<CartItemsContainer> | ||
{cartItems.length ? ( | ||
<div className="cart-items"> | ||
{cartItems.map((cartItem) => ( | ||
<CartItem key={cartItem.id} item={cartItem} /> | ||
))} | ||
</div> | ||
cartItems.map(cartItem => ( | ||
<CartItem key={cartItem.id} item={cartItem} /> | ||
)) | ||
) : ( | ||
<span className="empty-message">Your cart is empty</span> | ||
<EmptyMessageContainer>Your cart is empty</EmptyMessageContainer> | ||
)} | ||
<CustomButton | ||
onClick={() => { | ||
history.push("/checkout"); | ||
dispatch(toggleCartHidden()); | ||
}} | ||
> | ||
GO TO CHECKOUT | ||
</CustomButton> | ||
</div> | ||
); | ||
}; | ||
</CartItemsContainer> | ||
<CartDropdownButton | ||
onClick={() => { | ||
history.push('/checkout'); | ||
dispatch(toggleCartHidden()); | ||
}} | ||
> | ||
GO TO CHECKOUT | ||
</CartDropdownButton> | ||
</CartDropdownContainer> | ||
); | ||
|
||
const mapStateToProps = createStructuredSelector({ | ||
cartItems: selectCartItems, | ||
cartItems: selectCartItems | ||
}); | ||
|
||
// This below is also a selector without createStructuredSelector. | ||
// const mapStateToProps = (state) => ({ | ||
// cartItems: selectCartItems(state), | ||
// }); | ||
|
||
// This below is normal mapStateToProps in redux without selectors. | ||
// const mapStateToProps = ({ cart: { cartItems } }) => ({ // We used advanced destructuring to cartItems from cart. | ||
// cartItems, | ||
// }); | ||
|
||
export default withRouter(connect(mapStateToProps)(CartDropdown)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import styled from 'styled-components'; | ||
import CustomButton from '../custom-button/custom-button.component'; | ||
|
||
export const CartDropdownContainer = styled.div` | ||
position: absolute; | ||
width: 240px; | ||
height: 340px; | ||
display: flex; | ||
flex-direction: column; | ||
padding: 20px; | ||
border: 1px solid black; | ||
background-color: white; | ||
top: 90px; | ||
right: 40px; | ||
z-index: 5; | ||
`; | ||
|
||
export const CartDropdownButton = styled(CustomButton)` | ||
margin-top: auto; | ||
`; | ||
|
||
export const EmptyMessageContainer = styled.span` | ||
font-size: 18px; | ||
margin: 50px auto; | ||
`; | ||
|
||
export const CartItemsContainer = styled.div` | ||
height: 240px; | ||
display: flex; | ||
flex-direction: column; | ||
overflow: scroll; | ||
`; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,32 @@ | ||
import React from "react"; | ||
import { connect } from "react-redux"; | ||
import { createStructuredSelector } from "reselect"; | ||
|
||
import { toggleCartHidden } from "../../redux/cart/cart.actions"; | ||
import { selectCartItemsCount } from "../../redux/cart/cart.selectors"; | ||
|
||
import { ReactComponent as ShoppingIcon } from "../../assets/shopping-bag.svg"; | ||
|
||
import "./cart-icon.styles.scss"; | ||
|
||
const CartIcon = ({ toggleCartHidden, itemCount }) => { | ||
// toggleCartHidden coming from mapDispatchToProps | ||
return ( | ||
<div className="cart-icon" onClick={toggleCartHidden}> | ||
<ShoppingIcon className="shopping-icon" /> | ||
<span className="item-count">{itemCount}</span> | ||
</div> | ||
); | ||
}; | ||
|
||
const mapStateToProps = createStructuredSelector({ | ||
itemCount: selectCartItemsCount, | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { createStructuredSelector } from 'reselect'; | ||
|
||
import { toggleCartHidden } from '../../redux/cart/cart.actions'; | ||
import { selectCartItemsCount } from '../../redux/cart/cart.selectors'; | ||
|
||
import { | ||
CartContainer, | ||
ShoppingIcon, | ||
ItemCountContainer | ||
} from './cart-icon.styles'; | ||
|
||
const CartIcon = ({ toggleCartHidden, itemCount }) => ( | ||
<CartContainer onClick={toggleCartHidden}> | ||
<ShoppingIcon /> | ||
<ItemCountContainer>{itemCount}</ItemCountContainer> | ||
</CartContainer> | ||
); | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
toggleCartHidden: () => dispatch(toggleCartHidden()) | ||
}); | ||
|
||
// This below is also a selector without createStructuredSelector. | ||
// const mapStateToProps = (state) => ({ | ||
// itemCount: selectCartItemsCount(state), | ||
// }); | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
toggleCartHidden: () => dispatch(toggleCartHidden()), | ||
const mapStateToProps = createStructuredSelector({ | ||
itemCount: selectCartItemsCount | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(CartIcon); | ||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(CartIcon); |
Oops, something went wrong.