Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cart component #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { PureComponent } from 'react';
import PropTypes from 'prop-types';
import Restaurants from '../restaurants';
import Header from '../header';
import Cart from '../cart/cart';

export default class App extends PureComponent {
render() {
return (
<div>
<Header />
<Cart />
<Restaurants restaurants={this.props.restaurants} />
</div>
);
Expand Down
28 changes: 28 additions & 0 deletions src/components/cart/cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import styles from './cart.module.css';

import Button from '../button';

function Cart({ products, decrement, increment }) {
console.log(products);
return (
<div className={styles.cart}>
<h2>Cart</h2>
<ul>
{Object.keys(products).map((key, amount) => (
Copy link
Owner

@koretskiyav koretskiyav Dec 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

хорошее начало, это лучше, чем вообще не делать домашку

<li className={styles.product} key={key}>
<div className={styles.name}>{key}</div>
<div className={styles.amount}>{products[key]}</div>
</li>
))}
</ul>
</div>
);
}

const mapStateToProps = (state, props) => ({
products: state.order,
});

export default connect(mapStateToProps)(Cart);
24 changes: 24 additions & 0 deletions src/components/cart/cart.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.cart {
position: absolute;
right: 20px;
top: 20px;
background-color: #fff;
padding: 20px;
z-index: 100;
width: 400px;
}

.cart h2 {
text-align: center;
}

.cart ul {
padding: 0;
}

.product {
display: flex;
width: 100%;
justify-content: space-between;
align-items: center;
}
1 change: 1 addition & 0 deletions src/components/cart/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './cart';