-
Notifications
You must be signed in to change notification settings - Fork 20
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
Ht5 #67
base: master
Are you sure you want to change the base?
Ht5 #67
Changes from all commits
bcddb51
2bccd84
9e731e1
12c75ca
dcdb5c6
3d3a698
5eaa403
6c6a72f
39fc743
6023d46
1c6a878
84ec3f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import Product from '../product'; | ||
import Basket from '../basket'; | ||
import Loader from '../loader'; | ||
import { | ||
productsListSelector, | ||
productsLoadedSelector, | ||
productsLoadingSelector, | ||
} from '../../redux/selectors'; | ||
import { loadProducts } from '../../redux/actions'; | ||
|
||
import styles from './menu.module.css'; | ||
|
||
|
@@ -16,9 +24,23 @@ class Menu extends React.Component { | |
this.setState({ error }); | ||
} | ||
|
||
componentDidMount() { | ||
if (!this.props.loading && !this.props.loaded) { | ||
this.props.loadProducts(this.props.restaurantId); | ||
} | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (this.props.restaurantId !== prevProps.restaurantId) { | ||
this.props.loadProducts(this.props.restaurantId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут будет повторно грузиться для ресторана, для которого уже загружено |
||
} | ||
} | ||
|
||
render() { | ||
const { menu } = this.props; | ||
|
||
if (this.props.loading || !this.props.loaded) return <Loader />; | ||
|
||
if (this.state.error) { | ||
return <p>В этом ресторане меню не доступно</p>; | ||
} | ||
|
@@ -38,4 +60,19 @@ class Menu extends React.Component { | |
} | ||
} | ||
|
||
export default Menu; | ||
const mapStateToProps = (state) => ({ | ||
products: productsListSelector(state), | ||
loading: productsLoadingSelector(state), | ||
loaded: productsLoadedSelector(state), | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch, props) => ({ | ||
loadProducts: () => dispatch(loadProducts(props.restaurantId)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. restaurantId передается в componentDidMount |
||
}); | ||
|
||
//&& | ||
// !this.props.loading && | ||
// !this.props.loaded | ||
//connect(null, { loadProducts })( | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Menu); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import Menu from '../menu'; | ||
|
@@ -7,10 +7,22 @@ import Banner from '../banner'; | |
import Rate from '../rate'; | ||
import Tabs from '../tabs'; | ||
import { averageRatingSelector } from '../../redux/selectors'; | ||
import { loadReviews } from '../../redux/actions'; | ||
|
||
const Restaurant = ({ | ||
id, | ||
name, | ||
menu, | ||
reviews, | ||
averageRating, | ||
loadReviews, | ||
}) => { | ||
useEffect(() => { | ||
loadReviews(id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут будет повторно грузиться для ресторана, для которого уже загружено |
||
}, [loadReviews, id]); | ||
|
||
const Restaurant = ({ id, name, menu, reviews, averageRating }) => { | ||
const tabs = [ | ||
{ title: 'Menu', content: <Menu menu={menu} /> }, | ||
{ title: 'Menu', content: <Menu menu={menu} restaurantId={id} /> }, | ||
{ | ||
title: 'Reviews', | ||
content: <Reviews reviews={reviews} restaurantId={id} />, | ||
|
@@ -35,6 +47,9 @@ Restaurant.propTypes = { | |
averageRating: PropTypes.number, | ||
}; | ||
|
||
export default connect((state, props) => ({ | ||
averageRating: averageRatingSelector(state, props), | ||
}))(Restaurant); | ||
export default connect( | ||
(state, props) => ({ | ||
averageRating: averageRatingSelector(state, props), | ||
}), | ||
{ loadReviews } | ||
)(Restaurant); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут тоже нужна проверка на loading и loaded