-
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
ДЗ4 #63
base: master
Are you sure you want to change the base?
ДЗ4 #63
Changes from all commits
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.idea | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,52 @@ | ||
import React from 'react'; | ||
import React, { useMemo } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { makeGetReview, makeGetReviewUser } from '../../../redux/selectors'; | ||
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} /> | ||
const Review = ({ review, user }) => { | ||
const { text, rating } = review; | ||
const userName = useMemo(() => user.name || 'Anonymous', [user]); | ||
|
||
return ( | ||
<div className={styles.review} data-id="review"> | ||
<div className={styles.content}> | ||
<div> | ||
<h4 className={styles.name} data-id="review-user"> | ||
{userName} | ||
</h4> | ||
<p className={styles.comment} data-id="review-text"> | ||
{text} | ||
</p> | ||
</div> | ||
<div className={styles.rate}> | ||
<Rate value={rating} readOnly /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
); | ||
}; | ||
|
||
Review.propTypes = { | ||
user: PropTypes.string, | ||
text: PropTypes.string, | ||
rating: PropTypes.number.isRequired, | ||
review: PropTypes.shape({ | ||
text: PropTypes.string, | ||
rating: PropTypes.number.isRequired, | ||
}), | ||
user: PropTypes.shape({ | ||
name: PropTypes.string, | ||
}), | ||
}; | ||
|
||
Review.defaultProps = { | ||
user: 'Anonymous', | ||
const makeMapStateToProps = (initialState, { id }) => { | ||
const getReview = makeGetReview(id); | ||
const getReviewUser = makeGetReviewUser(id); | ||
|
||
return (state) => ({ | ||
review: getReview(state), | ||
user: getReviewUser(state), | ||
}); | ||
}; | ||
|
||
export default Review; | ||
export default connect(makeMapStateToProps)(Review); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import { INCREMENT, DECREMENT, REMOVE } from './constants'; | ||
import { INCREMENT, DECREMENT, REMOVE, CREATE_REVIEW } from './constants'; | ||
|
||
export const increment = (id) => ({ type: INCREMENT, payload: { id } }); | ||
export const decrement = (id) => ({ type: DECREMENT, payload: { id } }); | ||
export const remove = (id) => ({ type: REMOVE, payload: { id } }); | ||
export const createReview = (values, meta) => ({ | ||
type: CREATE_REVIEW, | ||
payload: { ...values }, | ||
meta, | ||
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. ну это не совсем meta, restaurantId скорее в payload должен идти |
||
}); |
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 CREATE_REVIEW = 'CREATE_REVIEW'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { v4 as generate } from 'uuid'; | ||
import { CREATE_REVIEW } from '../constants'; | ||
|
||
const generateId = (store) => (next) => (action) => { | ||
if (action.type === CREATE_REVIEW) { | ||
next({ | ||
...action, | ||
payload: { | ||
...action.payload, | ||
id: generate(), | ||
}, | ||
}); | ||
} else { | ||
next(action); | ||
} | ||
}; | ||
|
||
export default generateId; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { normalizedUsers } from '../../fixtures'; | ||
|
||
const defaultUsers = normalizedUsers.reduce( | ||
(acc, user) => ({ ...acc, [user.id]: user }), | ||
{} | ||
); | ||
|
||
const reducer = (users = 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. нету добавления пользователя по CREATE_REVIEW 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. а я сначала сделала, и 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. пользователь специально пишет свое имя, чтобы его запомнили :) |
||
default: | ||
return users; | ||
} | ||
}; | ||
|
||
export default reducer; |
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.
тут лучше не делать каррирования, а сделать
review: reviewSelecor(state, props)
На занятии расскажу почему