-
Notifications
You must be signed in to change notification settings - Fork 16
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
Feature/home task 4 #67
base: master
Are you sure you want to change the base?
Changes from all commits
27e2457
3c54cc6
0b914de
3bf3625
96f7c14
90526fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,17 @@ import Restaurant from '../restaurant'; | |
import Tabs from '../tabs'; | ||
|
||
function Restaurants({ restaurants }) { | ||
const [activeId, setActiveId] = useState(restaurants[0].id); | ||
const [firstKey] = Object.keys(restaurants); | ||
const [activeId, setActiveId] = useState(restaurants[firstKey].id); | ||
|
||
const tabs = useMemo( | ||
() => restaurants.map(({ id, name }) => ({ id, label: name })), | ||
() => Object.keys(restaurants).map((key) => { | ||
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. это вычисление лучше перенести в селекторы |
||
return {id: restaurants[key].id, label: restaurants[key].name}; | ||
}), | ||
[restaurants] | ||
); | ||
|
||
const activeRestaurant = useMemo( | ||
() => restaurants.find((restaurant) => restaurant.id === activeId), | ||
[activeId, restaurants] | ||
); | ||
const activeRestaurant = restaurants[activeId] | ||
|
||
return ( | ||
<div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,46 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import { connect } from 'react-redux'; | ||
import Rate from '../../rate'; | ||
import styles from './review.module.css'; | ||
|
||
const Review = ({ user, text, rating }) => ( | ||
<div className={styles.review} data-id="review"> | ||
<div className={styles.content}> | ||
<div> | ||
<h4 className={styles.name} data-id="review-user"> | ||
{user} | ||
</h4> | ||
<p className={styles.comment} data-id="review-text"> | ||
{text} | ||
</p> | ||
</div> | ||
<div className={styles.rate}> | ||
<Rate value={rating} /> | ||
function Review({review, users}) { | ||
const user = users[review?.userId] ? users[review?.userId] : null; | ||
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. это все необходимо вынести в селекторы |
||
return ( | ||
<div className={styles.review} data-id="review"> | ||
<div className={styles.content}> | ||
<div> | ||
<h4 className={styles.name} data-id="review-user"> | ||
{ user && user.name ? user.name : "Anonymous"} | ||
</h4> | ||
<p className={styles.comment} data-id="review-text"> | ||
{review && (review.text)} | ||
</p> | ||
</div> | ||
<div className={styles.rate}> | ||
{review && review.rating && (<Rate value={review.rating}/>)} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
); | ||
}; | ||
|
||
Review.propTypes = { | ||
user: PropTypes.string, | ||
text: PropTypes.string, | ||
rating: PropTypes.number.isRequired, | ||
review: PropTypes.shape({ | ||
user: PropTypes.string, | ||
text: PropTypes.string, | ||
rating: PropTypes.number.isRequired, | ||
}).isRequired, | ||
user: PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired | ||
}).isRequired | ||
}; | ||
|
||
Review.defaultProps = { | ||
user: 'Anonymous', | ||
const mapStateToProps = (state, props) => { | ||
return { | ||
review: state.reviews[props.reviewId], | ||
users: state.users | ||
} | ||
}; | ||
|
||
export default Review; | ||
export default connect(mapStateToProps)(Review); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { DECREMENT, INCREMENT, REMOVE } from './constants'; | ||
import { DECREMENT, INCREMENT, REMOVE, ADD_REVIEW } from './constants'; | ||
|
||
export const increment = (id) => ({ type: INCREMENT, id }); | ||
export const decrement = (id) => ({ type: DECREMENT, id }); | ||
export const remove = (id) => ({ type: REMOVE, id }); | ||
export const addReview = (params) => ({ type: ADD_REVIEW, payload: params}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const INCREMENT = 'INCREMENT'; | ||
export const DECREMENT = 'DECREMENT'; | ||
export const REMOVE = 'REMOVE'; | ||
export const ADD_REVIEW = 'ADD_REVIEW'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { ADD_REVIEW } from "../constants"; | ||
|
||
export default (store) => (next) => (action) => { | ||
if (action.type === ADD_REVIEW) { | ||
action.payload.id = uuidv4(); | ||
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. не стоит мутировать action, расскажу при разборе домашки почему |
||
action.payload.uuid = uuidv4(); | ||
} | ||
next(action); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { normalizedUsers } from '../../fixtures'; | ||
|
||
const defaultUsers = normalizedUsers.reduce( | ||
(acc, user) => ({ ...acc, [user.id]: user }), | ||
{} | ||
); | ||
|
||
export default (products = defaultUsers, action) => { | ||
const { type } = action; | ||
|
||
switch (type) { | ||
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. пропущено добавление нового юзера из ревью |
||
default: | ||
return products; | ||
} | ||
}; |
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.
тут необходимо использовать селекторы