-
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/ht6 #81
base: master
Are you sure you want to change the base?
Feature/ht6 #81
Changes from all commits
ae0b71e
908d210
634a8b1
1a065a2
37f4590
4b298ef
aa567ce
f6d85b2
b07f4d6
5e7aaf4
6feb884
aafe78f
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,19 +1,21 @@ | ||||||
import PropTypes from 'prop-types'; | ||||||
import cn from 'classnames'; | ||||||
import { NavLink } from 'react-router-dom'; | ||||||
|
||||||
import styles from './tabs.module.css'; | ||||||
|
||||||
function Tabs({ tabs, activeId, onChange }) { | ||||||
function Tabs({ tabs, activeId }) { | ||||||
return ( | ||||||
<div className={styles.tabs}> | ||||||
{tabs.map(({ id, label }) => ( | ||||||
<span | ||||||
{tabs.map(({ id, label, route }) => ( | ||||||
<NavLink | ||||||
key={id} | ||||||
className={cn(styles.tab, { [styles.active]: id === activeId })} | ||||||
onClick={() => onChange(id)} | ||||||
to={route} | ||||||
className={styles.tab} | ||||||
activeClassName={cn(styles.tab, { [styles.active]: id === activeId })} | ||||||
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.
Suggested change
|
||||||
> | ||||||
{label} | ||||||
</span> | ||||||
</NavLink> | ||||||
))} | ||||||
</div> | ||||||
); | ||||||
|
@@ -24,10 +26,10 @@ Tabs.propTypes = { | |||||
PropTypes.shape({ | ||||||
id: PropTypes.string.isRequired, | ||||||
label: PropTypes.string, | ||||||
route: PropTypes.string.isRequired, | ||||||
}).isRequired | ||||||
).isRequired, | ||||||
activeId: PropTypes.string, | ||||||
onChange: PropTypes.func.isRequired, | ||||||
}; | ||||||
|
||||||
export default Tabs; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
import { DECREMENT, INCREMENT, REMOVE } from '../constants'; | ||
|
||
// { [productId]: amount } | ||
// { [productId]: {amount, restId} } | ||
export default function (state = {}, action) { | ||
const { type, id } = action; | ||
const { type, id, restId } = action; | ||
switch (type) { | ||
case INCREMENT: | ||
return { ...state, [id]: (state[id] || 0) + 1 }; | ||
const item = state[id] || { restId, amount: 0 }; | ||
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 { | ||
...state, | ||
[id]: { ...item, amount: item.amount + 1 }, | ||
}; | ||
case DECREMENT: | ||
return { ...state, [id]: state[id] > 0 ? (state[id] || 0) - 1 : 0 }; | ||
return state[id] | ||
? { | ||
...state, | ||
[id]: { | ||
...state[id], | ||
amount: state[id].amount > 0 ? (state[id].amount || 0) - 1 : 0, | ||
}, | ||
} | ||
: state; | ||
case REMOVE: | ||
return { ...state, [id]: 0 }; | ||
return { ...state, [id]: { ...state[id], amount: 0 } }; | ||
default: | ||
return state; | ||
} | ||
|
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.
этот роутинг проще описать на уровне одного ресторана, будет немного аккуратнее, покажу на своей домашке