Skip to content

[react-restaurant] Created a react app for ramp-up#1

Open
OctaFloare wants to merge 38 commits intomasterfrom
react-restaurant
Open

[react-restaurant] Created a react app for ramp-up#1
OctaFloare wants to merge 38 commits intomasterfrom
react-restaurant

Conversation

@OctaFloare
Copy link
Copy Markdown
Owner

Description

Web app for a restaurant

Related

no link to Jira

Copy link
Copy Markdown

@miutamihai miutamihai left a comment

Choose a reason for hiding this comment

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

Before we can talk about the code itself, let's first fix the issues outlined in this review.

src/App.js Outdated
const App = () =>
<Provider store={store}>
<Router>
<NavBar />
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Let's indent these child components, so that it's clear they are contained within the <Router> component.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay

<Routes />
</Router>
</Provider>
export default App;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should always leave an empty line before exports.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay

import React, {useEffect, useState} from "react";
import {Box, Grid, Toolbar, Badge, IconButton} from "@material-ui/core";
import AddShoppingCartIcon from '@material-ui/icons/AddShoppingCart';
import 'bootstrap/dist/css/bootstrap-grid.css.map'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

image
I don't know what this import does for you, but the app wouldn't start on my machine with it. Maybe there's something missing in your package.json ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Package removed. It was not used

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay

<p>
Welcome to React Restaurant
</p>
<a className="App-link" href="http://localhost:3000/menu">
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Picture this scenario: I have another app running on port 3000 and so I try to run your app on another port (say 3001). This would lead me to 404 for every <a> tag in your app.

Maybe checkout this for linking in react-router

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay

export const NavBar = () =>
<AppBar position ='static'>
<Toolbar variant ='dense'>
<NavbarIcons link={'/'} icon={<MenuIcon/>} />
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

image
It's maybe a small detail, but this icon is pretty misleading, since before pressing it I thought it's gonna open a menu, but it redirected me to the / route. Maybe choose something else?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

image
Also is the application's title meant to be between your links? :)))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Yes

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Also, the misleading icon has been changed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay

<Box mr={5}>
<IconButton onClick={onClick}>
<Badge badgeContent={selected.length} color='secondary'>
<AddShoppingCartIcon />
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

image

Shouldn't the text be clickable too?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

image
Also clicking the icon while I have selected sandwiches does nothing :))))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The click on the icon adds them to the shopping-cart. To view the shopping-cart, you have to go to that page from the navbar , by clicking on the shopping-cart icon

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Also, the text is now clickable too.

Copy link
Copy Markdown

@miutamihai miutamihai left a comment

Choose a reason for hiding this comment

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

Some more stuff. Do these and we'll take yet another look.

const data = useSelector(selector)
const onClick = useOnAddCart(selected,setSelected, selector);

const options = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We can maybe extract this huge options object in a different hook.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

};

return <Box mt={5} mr={2}>
<Grid container direction='row' justify='center' spacing={2}>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Indentation ...

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

}

const selector = ({ sandwichMenuReducer }) => {
console.log(sandwichMenuReducer)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Forgotten console.log ? :)))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done


const [selected, setSelected] = useState([]);
const dispatch = useDispatch()
useEffect(() => dispatch(getAllSandwiches()),[])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

image
Maybe this is what should happen in the useInit hook :)))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

}
return <Box m={5}>
<MUIDataTable
data={shoppingCartData}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

image
These are duplicate. Maybe we should add a quantity column to the table? Then, if the user adds the same item multiple times, it won't be duplicated like this.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

</Box>
}

const selector = ({ shoppingCartReducer }) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This callback can be rewritten like this:

const selector = ({ shoppingCartReducer }) => shoppingCartReducer.items 

This applies to all callbacks that contain just a return statement.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done



export const addItemToShoppingCart = item => ({type: ADD_ITEM_TO_SHOPPING_CART, payload: item})
export const removeItemFromShoppingCart = remainingItems =>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

image

Let's move the remove action to a different file.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

image
Also, since we pass the items to remove to the action, not the remaining items, maybe rename this parameter?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also, since we pass a multitude of items to these afore-mentioned actions, maybe rename them like this:

  • addItemToShoppingCart -> addItems
  • removeItemFromShoppingCart -> removeItems

We can also omit the ShoppingCart part since we're already in the context of the shopping-cart directory:
image

If you really want more context, you can import them using an alias like this:
import { addItems as addItemsToShoppingCart } from 'whatever'

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

import {useState} from "react";

export const useDefaultSandwichMenu = () => {
const [data, setData] = useState([])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we ever use these data and setData?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

import {useDispatch, useSelector} from "react-redux";
import {addItemToShoppingCart} from "../../../shopping-cart/actions"

export const useOnAddCart = (selected, setSelected, selector) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This hook looks ...smelly. Let's move the selected, setSelected pair to the sandwich context.

image

Also this mapping can be done inside the reducer.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

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