Skip to content
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

HT6 #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

HT6 #51

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@
5. При загрузках показывать лоадеры, все грузить максимально низко, там где эти данные нужны
6. Все данные грузить только один раз (не загружать повторно данные, которые уже есть)
7. (Опционально) переписать все на **immer**

# HT6

1. Сделать reviews/menu отдельными роутами (/restaurant/:id/reviews)
2. В корзине сделать продукты линками на их ресторан
4 changes: 3 additions & 1 deletion src/components/basket/basket.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ function Basket({ title = 'Basket', total, orderProducts }) {
return (
<div className={styles.basket}>
<h4 className={styles.title}>{title}</h4>
{orderProducts.map(({ product, amount, subtotal }) => (
{orderProducts.map(({ product, amount, subtotal, restaurantId }) => (
<Link to={`/restaurants/${restaurantId}/menu`} >
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

правильнее было бы завернуть именно имя продукта внутри компонента BasketItem, чтобы кнопки +/-/х остались без ссылок

<BasketItem
product={product}
amount={amount}
key={product.id}
subtotal={subtotal}
/>
</Link>
))}
<hr className={styles.hr} />
<div className={itemStyles.basketItem}>
Expand Down
21 changes: 12 additions & 9 deletions src/components/restaurant/restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,33 @@ import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { createStructuredSelector } from 'reselect';
import {Route, NavLink} from 'react-router-dom';

import Menu from '../menu';
import Reviews from '../reviews';
import Banner from '../banner';
import Rate from '../rate';
import Tabs from '../tabs';
import { averageRatingSelector } from '../../redux/selectors';
import styles from './restaurant.module.css';

const Restaurant = ({ restaurant, averageRating }) => {
const { id, name, menu, reviews } = restaurant;
const tabs = [
{ title: 'Menu', content: <Menu menu={menu} restaurantId={id} /> },
{
title: 'Reviews',
content: <Reviews reviews={reviews} restaurantId={id} />,
},
];

return (
<div>
<Banner heading={name}>
{!!averageRating && <Rate value={averageRating} />}
</Banner>
<Tabs tabs={tabs} />
<div className={styles.nav}>
<NavLink to={`/restaurants/${id}/menu`} activeClassName={styles.active} className={styles.item}>Menu</NavLink>
<NavLink to={`/restaurants/${id}/reviews`} activeClassName={styles.active} className={styles.item}>Reviews</NavLink>
</div>
<Route path="/restaurants/:restId/menu">
<Menu menu={menu} restaurantId={id} />
</Route>
<Route path="/restaurants/:restId/reviews">
<Reviews reviews={reviews} restaurantId={id} />
</Route>
</div>
);
};
Expand Down
14 changes: 14 additions & 0 deletions src/components/restaurant/restaurant.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.nav {
height: auto;
text-align: center;
padding: 12px;
background-color: var(--grey);
}

.item {
padding: 4px 12px;
}

.item.active {
border-bottom: 1px solid var(--black);
}
2 changes: 1 addition & 1 deletion src/components/restaurants/restaurants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Restaurants = ({ restaurants, match }) => {
<NavLink
key={id}
className={styles.tab}
to={`/restaurants/${id}`}
to={`/restaurants/${id}/menu`}
activeClassName={styles.active}
>
{name}
Expand Down
12 changes: 11 additions & 1 deletion src/redux/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const reviewSelector = getById(reviewsSelector);
export const orderProductsSelector = createSelector(
productsSelector,
orderSelector,
(products, order) =>
restaurantsListSelector,
(products, order, restaurants) =>
Object.keys(order)
.filter((productId) => order[productId] > 0)
.map((productId) => products[productId])
Expand All @@ -44,6 +45,15 @@ export const orderProductsSelector = createSelector(
amount: order[product.id],
subtotal: order[product.id] * product.price,
}))
.map((orderProduct) => {
const restaurant = restaurants.find(restaurant =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот это вычисление лучше вынести в отдельный селектор, чтобы не вычислять это при любом изменении заказа

undefined !== restaurant.menu.find(item => item === orderProduct.product.id)
)
return {
...orderProduct,
restaurantId: restaurant.id,
}
})
);

export const totalSelector = createSelector(
Expand Down