[react-restaurant] Created a react app for ramp-up#1
[react-restaurant] Created a react app for ramp-up#1OctaFloare wants to merge 38 commits intomasterfrom
Conversation
miutamihai
left a comment
There was a problem hiding this comment.
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 /> |
There was a problem hiding this comment.
Let's indent these child components, so that it's clear they are contained within the <Router> component.
| <Routes /> | ||
| </Router> | ||
| </Provider> | ||
| export default App; |
There was a problem hiding this comment.
We should always leave an empty line before exports.
| 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' |
There was a problem hiding this comment.
Package removed. It was not used
src/home/home.jsx
Outdated
| <p> | ||
| Welcome to React Restaurant | ||
| </p> | ||
| <a className="App-link" href="http://localhost:3000/menu"> |
There was a problem hiding this comment.
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
src/core/navbar/navbar.jsx
Outdated
| export const NavBar = () => | ||
| <AppBar position ='static'> | ||
| <Toolbar variant ='dense'> | ||
| <NavbarIcons link={'/'} icon={<MenuIcon/>} /> |
There was a problem hiding this comment.
Also, the misleading icon has been changed.
| <Box mr={5}> | ||
| <IconButton onClick={onClick}> | ||
| <Badge badgeContent={selected.length} color='secondary'> | ||
| <AddShoppingCartIcon /> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Also, the text is now clickable too.
miutamihai
left a comment
There was a problem hiding this comment.
Some more stuff. Do these and we'll take yet another look.
| const data = useSelector(selector) | ||
| const onClick = useOnAddCart(selected,setSelected, selector); | ||
|
|
||
| const options = { |
There was a problem hiding this comment.
We can maybe extract this huge options object in a different hook.
| }; | ||
|
|
||
| return <Box mt={5} mr={2}> | ||
| <Grid container direction='row' justify='center' spacing={2}> |
| } | ||
|
|
||
| const selector = ({ sandwichMenuReducer }) => { | ||
| console.log(sandwichMenuReducer) |
|
|
||
| const [selected, setSelected] = useState([]); | ||
| const dispatch = useDispatch() | ||
| useEffect(() => dispatch(getAllSandwiches()),[]) |
| } | ||
| return <Box m={5}> | ||
| <MUIDataTable | ||
| data={shoppingCartData} |
| </Box> | ||
| } | ||
|
|
||
| const selector = ({ shoppingCartReducer }) => { |
There was a problem hiding this comment.
This callback can be rewritten like this:
const selector = ({ shoppingCartReducer }) => shoppingCartReducer.items
This applies to all callbacks that contain just a return statement.
|
|
||
|
|
||
| export const addItemToShoppingCart = item => ({type: ADD_ITEM_TO_SHOPPING_CART, payload: item}) | ||
| export const removeItemFromShoppingCart = remainingItems => |
There was a problem hiding this comment.
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:

If you really want more context, you can import them using an alias like this:
import { addItems as addItemsToShoppingCart } from 'whatever'
| import {useState} from "react"; | ||
|
|
||
| export const useDefaultSandwichMenu = () => { | ||
| const [data, setData] = useState([]) |
There was a problem hiding this comment.
Do we ever use these data and setData?
| import {useDispatch, useSelector} from "react-redux"; | ||
| import {addItemToShoppingCart} from "../../../shopping-cart/actions" | ||
|
|
||
| export const useOnAddCart = (selected, setSelected, selector) => { |










Description
Web app for a restaurant
Related
no link to Jira