-
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
Lesson7 #91
base: master
Are you sure you want to change the base?
Lesson7 #91
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 |
---|---|---|
@@ -1,14 +1,31 @@ | ||
import { useContext } from 'react'; | ||
import cn from 'classnames'; | ||
import { Link } from 'react-router-dom'; | ||
import { userContext } from '../../contexts/user-context'; | ||
import { ReactComponent as Logo } from '../../icons/logo.svg'; | ||
import { | ||
currDictionary, | ||
currencyContext, | ||
} from '../../contexts/currency-context'; | ||
import styles from './header.module.css'; | ||
|
||
const Header = () => { | ||
const { name, setName } = useContext(userContext); | ||
const { current, setCurrent } = useContext(currencyContext); | ||
|
||
return ( | ||
<header className={styles.header} onClick={() => setName('Igor')}> | ||
<div className={styles.tabs}> | ||
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. лучше это вынести в отдельный компонент |
||
{Object.entries(currDictionary).map(([id, curr]) => ( | ||
<span | ||
key={id} | ||
className={cn(styles.tab, { [styles.active]: id === current })} | ||
onClick={() => setCurrent(id)} | ||
> | ||
{curr.name} | ||
</span> | ||
))} | ||
</div> | ||
<Link to="/restaurants"> | ||
<Logo /> | ||
</Link> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './money'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { | ||
CurrencyConsumer, | ||
getMoneyInCurr, | ||
currDictionary, | ||
} from '../../contexts/currency-context'; | ||
|
||
export default function Money({ value }) { | ||
return ( | ||
<CurrencyConsumer> | ||
{({ current }) => getMoneyInCurr(value, current, currDictionary)} | ||
</CurrencyConsumer> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './order-error'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { connect } from 'react-redux'; | ||
import { chechoutErrorSelector } from '../../redux/selectors'; | ||
|
||
const OrderError = ({ error = '' }) => { | ||
return ( | ||
<div> | ||
<h2>Wrong order!</h2> | ||
<p>{error}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
const mapStateToProps = (state) => ({ | ||
error: chechoutErrorSelector(state), | ||
}); | ||
|
||
export default connect(mapStateToProps)(OrderError); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { connect } from 'react-redux'; | |
import PropTypes from 'prop-types'; | ||
import styles from './product.module.css'; | ||
import Button from '../button'; | ||
import Money from '../money'; | ||
import { decrement, increment } from '../../redux/actions'; | ||
import { amountSelector, productSelector } from '../../redux/selectors'; | ||
|
||
|
@@ -12,12 +13,14 @@ function Product({ product, amount, decrement, increment }) { | |
<div> | ||
<h4 className={styles.title}>{product.name}</h4> | ||
<p className={styles.description}>{product.ingredients.join(', ')}</p> | ||
<div className={styles.price}>{product.price} $</div> | ||
<div className={styles.price}> | ||
<Money value={product.price} /> | ||
</div> | ||
</div> | ||
<div> | ||
<div className={styles.counter}> | ||
<div className={styles.count} data-id="product-amount"> | ||
{amount} | ||
<Money value={amount} /> | ||
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. это количество в штуках, а не в валюте :) |
||
</div> | ||
<div className={styles.buttons}> | ||
<Button | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.review-enter { | ||
opacity: 0.2; | ||
background-color: blue; | ||
transform: scale(0.8); | ||
} | ||
|
||
.review-enter-active { | ||
opacity: 1; | ||
background-color: #8e44ad; | ||
transform: translateX(0); | ||
transition: opacity 500ms, background-color 500ms, transform 500ms; | ||
} | ||
|
||
.review-exit { | ||
opacity: 1; | ||
} | ||
|
||
.review-exit-active { | ||
opacity: 0; | ||
transform: scale(0.9); | ||
transition: opacity 500ms, transform 500ms; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { useEffect } from 'react'; | ||
import { CSSTransition, TransitionGroup } from 'react-transition-group'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import Review from './review'; | ||
import Loader from '../loader'; | ||
import ReviewForm from './review-form'; | ||
import styles from './reviews.module.css'; | ||
import './review.css'; | ||
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. необходимо было сделать вариант через css modules |
||
|
||
import { loadReviews, loadUsers } from '../../redux/actions'; | ||
import { | ||
|
@@ -29,10 +31,14 @@ const Reviews = ({ | |
|
||
return ( | ||
<div className={styles.reviews}> | ||
{reviews.map((id) => ( | ||
<Review key={id} id={id} /> | ||
))} | ||
<ReviewForm restId={restId} /> | ||
<TransitionGroup> | ||
{reviews.map((id) => ( | ||
<CSSTransition key={id} timeout={2000} classNames="review"> | ||
<Review id={id} /> | ||
</CSSTransition> | ||
))} | ||
<ReviewForm restId={restId} /> | ||
</TransitionGroup> | ||
</div> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createContext } from 'react'; | ||
|
||
export const currDictionary = { | ||
ruble: { | ||
name: 'руб.', | ||
rateToDollar: 70, | ||
}, | ||
dollar: { | ||
name: '$', | ||
rateToDollar: 1, | ||
}, | ||
euro: { | ||
name: 'eur.', | ||
rateToDollar: 0.8, | ||
}, | ||
}; | ||
|
||
export const getMoneyInCurr = (value, curr, currDictionary) => { | ||
const countedVal = value * currDictionary[curr].rateToDollar; | ||
const roundedVal = parseInt(countedVal * 100) / 100; | ||
return `${roundedVal} ${currDictionary[curr].name}`; | ||
}; | ||
|
||
export const currencyContext = createContext(); | ||
|
||
export const CurrencyProvider = currencyContext.Provider; | ||
export const CurrencyConsumer = currencyContext.Consumer; |
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.
Не стоит данные контекста хранить в состоянии нашего приложения. Покажу как это можно сделать удобнее на своей домашке.