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

Task 5: add all functionality from task #2

Merged
merged 13 commits into from
Nov 8, 2021
Merged

Task 5: add all functionality from task #2

merged 13 commits into from
Nov 8, 2021

Conversation

vladyslavdmytrenko
Copy link
Owner

No description provided.

@vladyslavdmytrenko vladyslavdmytrenko changed the title Task 5: add all functionality from task Task 5: add all functionality from task Nov 3, 2021

const BasketButton = (props) => {
return (
<div className={style.container} onClick={() => props.toggleBasketDetail()}>
<BasketIcon className={style.icon} />
{props.countItems ? (
{props.countItems > 0 && (
Copy link

Choose a reason for hiding this comment

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

You can also convert to boolean in the following way: !!props.countItems

@@ -1,133 +1,58 @@
import React from 'react';

import Logo from 'components/common/Logo';
import Search from 'components/Search';
Copy link

Choose a reason for hiding this comment

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

The folder is called search (lower case)

Also for the following imports:

  • App
  • Basket
  • BasketDetails
  • BasketButton
  • BasketDetailItem

@@ -1,17 +1,27 @@
import React from 'react';

import style from './BasketDetailItem.module.css';
import Loader from 'components/common/Loader';
import { ReactComponent as DeleteIcon } from '../../../../assets/images/delete.svg';
Copy link

Choose a reason for hiding this comment

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

You can use absolute path here


import style from './Dish.module.css';

class Dish extends React.Component {
Copy link

Choose a reason for hiding this comment

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

As this component renders many dishes more suitable component name will be Dishes

@@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"axios": "^0.24.0",
Copy link

Choose a reason for hiding this comment

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

I suppose that json-server is installed globally.
Let's add json-server to dev project dependecies and create a script in package.json that will start it.

src/api/data.js Outdated
@@ -0,0 +1,5 @@
import axios from 'axios';

export default axios.create({
Copy link

Choose a reason for hiding this comment

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

Let's create a response interceptor that will return response.data

Example: https://www.npmjs.com/package/axios#interceptors (Interceptors section)

src/api/data.js Outdated
import axios from 'axios';

export default axios.create({
baseURL: 'http://localhost:3000/',
Copy link

Choose a reason for hiding this comment

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

}
}

_loadInitDishes = async () => {
Copy link

Choose a reason for hiding this comment

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

I do not recommend using underscores in methos naming because underscore indicates that the method is private which is really not.
Also, if you are interested in more details you can check it here:
airbnb/javascript#1024
airbnb/javascript#490

price: newItem.price,
count: 1,
};
await dataApi.post('basket', results);
Copy link

Choose a reason for hiding this comment

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

Imagine the case when dataApi.put('basket') (line 81) completed successfully, but dataApi.post('basket') not.
Then the data in json file will be updated, but not on the UI becase setting the data to the state is located after post API call

@vercel
Copy link

vercel bot commented Nov 4, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/vladyslavdmytrenko/project-1/AwvkL4LqPyyW5dhEocTwf5ByVrUV
✅ Preview: https://project-1-git-task5-vladyslavdmytrenko.vercel.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants