Skip to content

Lecture 10/hw #2

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions src/app/dish/[dishId]/loading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Loader } from "@/components/loader/component";


export default function Loading() {
return <Loader />;
}
16 changes: 16 additions & 0 deletions src/app/dish/[dishId]/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

import { DishContainer } from "@/components/dish/container";
import styles from "./styles.module.scss";
import { Ingredients } from "@/components/ingredients/component";
import { getDishById } from "@/services/api";

export default async function DishPage({params}) {
const dish = await getDishById(params.dishId);

return (
<div className={styles.root}>
<DishContainer dish={dish} className={styles.dish} />
<Ingredients ingredients={dish.ingredients} />
</div>
);
}
10 changes: 10 additions & 0 deletions src/app/dish/[dishId]/styles.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// .root {
// background-color: rgb(209, 253, 253);
// height: 100%;
// display: grid;
// grid-template-rows: auto 1fr auto;
// min-height: 100vh;
// }
.root {
margin: 10px 20px;
}
16 changes: 6 additions & 10 deletions src/app/page.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import styles from "./styles.module.scss";
export default function HomePage() {
return (
<div>HomePage</div>
)
}

export default function Home() {
return (
<main className={styles.main}>
<div className={styles.description}>
Home page
</div>
</main>
)
}

1 change: 0 additions & 1 deletion src/app/restaurants/[restaurantId]/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Restaurant } from '@/components/restaurant/component';

const Layout = async ({ children, params }) => {
const restaurant = await getRestaurantById(params.restaurantId);

return (
<div>
<Restaurant restaurant={restaurant}/>
Expand Down
2 changes: 1 addition & 1 deletion src/app/restaurants/[restaurantId]/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { Loader } from "@/components/loader/component";


export default function Loading() {
return <Loader />
return <Loader />;
}
16 changes: 0 additions & 16 deletions src/app/restaurants/[restaurantId]/menu/layout.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/restaurants/[restaurantId]/menu/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { Loader } from "@/components/loader/component";


export default function Loading() {
return <Loader />
return <Loader />;
}
12 changes: 7 additions & 5 deletions src/app/restaurants/[restaurantId]/page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { redirect } from 'next/navigation';

export default function RestaurantPage({ params }) {
return (
null
)
}
const RestaurantPage = ({params}) => {
redirect(params.restaurantId+'/menu');

};

export default RestaurantPage;
2 changes: 1 addition & 1 deletion src/app/restaurants/[restaurantId]/reviews/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { Loader } from "@/components/loader/component";


export default function Loading() {
return <Loader />
return <Loader />;
}
15 changes: 6 additions & 9 deletions src/app/restaurants/[restaurantId]/reviews/page.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { getReviewsByRestaurantId } from "@/services/api";
import { Reviews } from '@/components/reviews/component';
import { ReviewsContainer } from '@/components/reviews/container';

export default async function ReviewPage({params}) {
const restaurantId = params.restaurantId;
const reviews = await getReviewsByRestaurantId(restaurantId);
return (
<Reviews reviews={reviews}/>
)
}
export default async function ReviewPage({ params }) {
const restaurantId = params.restaurantId;

return <ReviewsContainer restaurantId={restaurantId}/>;
}
2 changes: 1 addition & 1 deletion src/app/restaurants/loading.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Loader } from "@/components/loader/component";

export default function Loading() {
return <Loader />
return <Loader />;
}
1 change: 1 addition & 0 deletions src/app/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
display: grid;
grid-template-rows: auto 1fr auto;
min-height: 100vh;

}
6 changes: 4 additions & 2 deletions src/components/button/component.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use client";
import { memo } from 'react';
import styles from './styles.module.scss';
import classNames from "classnames";

Expand All @@ -8,4 +8,6 @@ export const Button = ({ onClick, children, className, disabled, rootRef }) => {
{children}
</button>
);
};
};

export const ButtonMemoized = memo(Button);
3 changes: 2 additions & 1 deletion src/components/button/styles.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.root {
min-width: 30px;
min-width: fit-content;
width: 30px;
cursor: pointer;
border: none;
border-radius: 10px;
Expand Down
1 change: 0 additions & 1 deletion src/components/cart/container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import { selectCartProductIds } from "@/redux/ui/cart";

export const CartContainer = () => {
const dishIds = useSelector(selectCartProductIds);
console.log(dishIds);
return <Cart productIds={dishIds} />
}
17 changes: 10 additions & 7 deletions src/components/control-tabs/component.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@

"use client" ;
import Link from 'next/link';
import { Button } from '../button/component';
import { ButtonMemoized } from '../button/component';
import styles from './styles.module.scss';
import { usePathname } from 'next/navigation';

export const ControlTabs = ({ restaurantId }) => {
return (
<div >
const pathname = usePathname();
const isActiveMenu = pathname.endsWith("/menu");
const isActiveReview = pathname.endsWith("/reviews");

return (
<div>
<Link href={`/restaurants/${restaurantId}/menu`} className={styles.pageLink}>
<Button>Menu</Button>
<ButtonMemoized disabled={isActiveMenu}>Menu</ButtonMemoized>
</Link>


<Link href={`/restaurants/${restaurantId}/reviews`} className={styles.pageLink}>
<Button>Review</Button>
<ButtonMemoized disabled={isActiveReview}>Review</ButtonMemoized>
</Link>
</div>
);
Expand Down
15 changes: 15 additions & 0 deletions src/components/create-review-form/container.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use client";
import { useContext } from 'react';
import { UserContext } from "@/context/user-provider";
import { ReviewForm } from "../review-form/component";

export const CreateReviewFormContainer = ({onSave }) => {

const { name, id } = useContext(UserContext);

if (!name) {
return null;
}

return <ReviewForm userName={name} userId={id} onSave={onSave}/>;
}
17 changes: 9 additions & 8 deletions src/components/dish/cart-container.jsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import style from './styles.module.scss';
import { Button } from '../button/component';
import { ButtonMemoized } from '../button/component';
import { useDispatch, useSelector } from 'react-redux';
import { decrement, increment, selectProductAmountById } from '../../redux/ui/cart';
import { useCallback } from 'react';

export const DishCartContainer = ({ dishId }) => {
const amount = useSelector((state) =>
selectProductAmountById(state, dishId)
);
const dispatch = useDispatch();
const handleDecrement = () => {

const handleDecrement = useCallback(() => {
dispatch(decrement(dishId));
};
}, [dispatch, dishId]);

const handleIncrement = () => {
const handleIncrement = useCallback(() => {
dispatch(increment(dishId));
};

}, [dispatch, dishId]);
return (

<div className={style.root}>
<div>{dishId}</div>
<div className={style.buttonContainer}>
<Button className={style.button} onClick={handleDecrement} disabled={amount === 0}>-</Button>
<ButtonMemoized className={style.button} onClick={handleDecrement} disabled={amount === 0}>-</ButtonMemoized>
<p>{amount}</p>
<Button className={style.button} onClick={handleIncrement} disabled={amount === 5}>+</Button>
<ButtonMemoized className={style.button} onClick={handleIncrement} disabled={amount === 5}>+</ButtonMemoized>
</div>
</div>
);
Expand Down
8 changes: 6 additions & 2 deletions src/components/dish/component.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Link from "next/link";

export const Dish = ({ dish, className }) => {

return (
<div >
<div className={className}>{dish.name}</div>
<div className={className}>{dish.price}</div>
<Link href={`/dish/${dish.id}`}>
<div className={className}>{dish.name}</div>
<div className={className}>{dish.price}</div>
</Link>
</div>
);
};
17 changes: 8 additions & 9 deletions src/components/dish/container.jsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@

"use client";
import { decrement, increment, selectProductAmountById } from '@/redux/ui/cart';
import { Button } from '../button/component';
import { ButtonMemoized } from '../button/component';
import { Dish } from './component';
import styles from './styles.module.scss';
import { useDispatch, useSelector } from 'react-redux';
import { useCallback } from 'react';

export const DishContainer = ({ dish, className }) => {
const amount = useSelector((state) =>
selectProductAmountById(state, dish.id)
);
const dispatch = useDispatch();

const handleDecrement = () => {
const handleDecrement = useCallback(() => {
dispatch(decrement(dish.id));
};
}, [dispatch, dish.id]);

const handleIncrement = () => {
const handleIncrement = useCallback(() => {
dispatch(increment(dish.id));
};
}, [dispatch, dish.id]);

return (

<div className={styles.root}>
{/* <NavLink className={styles.link} to={`/dish/${dish.id}`}> */}
<Dish dish={dish} className={className} />
{/* </NavLink> */}
<div className={styles.buttonContainer}>
<Button className={styles.button} onClick={handleDecrement} disabled={amount === 0}>-</Button>
<ButtonMemoized className={styles.button} onClick={handleDecrement} disabled={amount === 0}>-</ButtonMemoized>
<p>{amount}</p>
<Button className={styles.button} onClick={handleIncrement} disabled={amount === 5}>+</Button>
<ButtonMemoized className={styles.button} onClick={handleIncrement} disabled={amount === 5}>+</ButtonMemoized>
</div>
</div>
);
Expand Down
10 changes: 2 additions & 8 deletions src/components/header/component.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import styles from './styles.module.scss';
import Link from 'next/link';
import classNames from 'classnames';
import { User } from '../user/component';
import { CartButtonContainer } from '../cart-button/container';
import { useSelector } from 'react-redux';
import { selectProductAmount } from '@/redux/ui/cart';


export const Header = () => {
return (
Expand All @@ -14,10 +10,8 @@ export const Header = () => {
<Link href="/restaurants" className={styles.link}>Restaurants</Link>
<Link href="/contacts" className={styles.link}>Contacts</Link>
<Link href="/about-us" className={styles.link}>About us</Link>
<div className={styles.user}>
<User />
<CartButtonContainer />
</div>
<User />
<CartButtonContainer />
</header>
);
};
5 changes: 0 additions & 5 deletions src/components/header/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
padding: 10px 20px;
}

.user {
display: flex;

}

.button {
margin-right: 5px;
}
Expand Down
10 changes: 10 additions & 0 deletions src/components/ingredients/component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

export const Ingredients = ({ ingredients }) => {
return (
<>
<h2>Ingredients:</h2>
{ingredients.map((ingredient, index) => (
<div key={index}>{ingredient}</div>
))}
</>
)};
6 changes: 3 additions & 3 deletions src/components/loader/component.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import classNames from "classnames";

import styles from "./styles.module.scss";

export const Loader = ({className}) => {
return <div className={classNames(styles.root, className)}></div>;
export const Loader = () => {
return <div className={styles.root}></div>;
};
1 change: 0 additions & 1 deletion src/components/loader/styles.module.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.root {
display: flex;
width: 100%;
Expand Down
Loading