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

[redux-observable] added redux observable #2

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
cb8210a
[react-restaurant] Added navbar
OctaFloare Mar 1, 2021
5aa01d0
[react-restaurant] Added routes
OctaFloare Mar 1, 2021
08f7f53
[react-restaurant] Added project images
OctaFloare Mar 1, 2021
e66611c
[react-restaurant] Added home page
OctaFloare Mar 1, 2021
ce29a8a
[react-restaurant] Added menu page
OctaFloare Mar 1, 2021
fdd3c4d
[react-restaurant] Added sandwich page
OctaFloare Mar 1, 2021
9c1325c
[react-restaurant] Added shopping-cart page
OctaFloare Mar 1, 2021
6ca5391
[react-restaurant] Added redux
OctaFloare Mar 1, 2021
99813cb
[react-restaurant] Added init-behaviour menu page
OctaFloare Mar 1, 2021
d96c6cb
[react-restaurant] Updated package.json
OctaFloare Mar 1, 2021
7248687
[react-restaurant] Updated App.js
OctaFloare Mar 1, 2021
f25f5e5
[react-restaurant] Follow-up remove unused package
OctaFloare Mar 1, 2021
219cf6d
[react-restaurant] Follow-up change <a> with <Link>
OctaFloare Mar 1, 2021
d224075
[react-restaurant] Follow-up change misleading icon
OctaFloare Mar 1, 2021
db4621b
[react-restaurant] Follow-up fix app.js
OctaFloare Mar 1, 2021
6af0b5a
[react-restaurant] Follow-up clickable text has been added.
OctaFloare Mar 1, 2021
9361865
[react-restaurant] Follow-up fix indentation
OctaFloare Mar 2, 2021
53f711c
[react-restaurant] Follow-up remove console.log
OctaFloare Mar 2, 2021
0878196
[react-restaurant] Follow-up make one-liner
OctaFloare Mar 2, 2021
8dc3cce
[react-restaurant] Follow-up rename actions
OctaFloare Mar 2, 2021
ad7bb60
[react-restaurant] Follow-up separate remove action
OctaFloare Mar 2, 2021
56f1b7c
[react-restaurant] Follow-up remove unused context variables
OctaFloare Mar 2, 2021
6036e98
[react-restaurant] Follow-up move selected in context
OctaFloare Mar 2, 2021
134fa50
[react-restaurant] Follow-up added shopping cart context
OctaFloare Mar 2, 2021
e4391c7
[react-restaurant] Follow-up place options in hook
OctaFloare Mar 2, 2021
b49dda6
[react-restaurant] Follow-up move logic to reducers
OctaFloare Mar 2, 2021
56550c8
[react-restaurant] Follow-up add countable rows
OctaFloare Mar 3, 2021
7ac25e6
[react-restaurant] Follow-up remove unused imports
OctaFloare Mar 9, 2021
0e9e585
[react-restaurant] Follow-up added get sandwiches api thunk
OctaFloare Mar 9, 2021
a7ec3a1
[react-restaurant] Follow-up added columns for new info
OctaFloare Mar 9, 2021
d9ee115
[react-restaurant] Follow-up added packages
OctaFloare Mar 9, 2021
1a59f08
[react-restaurant] Follow-up added get rate from api
OctaFloare Mar 9, 2021
8419088
[react-restaurant] Follow-up extract component
OctaFloare Mar 9, 2021
267932e
[react-restaurant] Follow-up added key to mapping
OctaFloare Mar 9, 2021
1448012
[react-restaurant] Follow-up change badge to navbar
OctaFloare Mar 9, 2021
170fc7c
[react-restaurant] Follow-up remove line break
OctaFloare Mar 9, 2021
471f1db
[react-restaurant] Follow-up add yup validation to reducers
OctaFloare Mar 9, 2021
c557421
[react-restaurant] Follow-up remove initial state
OctaFloare Mar 9, 2021
e38d7f0
[redux-observable] added epic middleware
OctaFloare Mar 10, 2021
e905041
[redux-observable] added sandwich epic
OctaFloare Mar 10, 2021
26b10ce
[redux-observable] added rate epic
OctaFloare Mar 10, 2021
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
909 changes: 909 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"@testing-library/user-event": "^12.7.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router": "^5.2.0",
"react-scripts": "4.0.2",
"redux-thunk": "^2.3.0",
"web-vitals": "^1.1.0"
},
"scripts": {
Expand All @@ -34,5 +36,23 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"axios": "^0.21.1",
"graphql": "^15.5.0",
"history": "^4.10.1",
"immutable": "^4.0.0-rc.12",
"lodash": "^4.17.21",
"mui-datatables": "^3.7.6",
"react-bootstrap": "^1.5.0",
"react-image-resizer": "^1.3.0",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"redux": "^4.0.5",
"yup": "^0.32.9",
"redux-observable": "^1.2.0",
"rxjs": "^6.6.6"
}
}
32 changes: 31 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,38 @@

.App-link {
color: #61dafb;
text-align: center;
justify-content: center;
}
.FoodTypeLink{
color: black;
text-align: center;
}
.fullPage{
padding: 120px 0;
position: relative;
min-height: 65vh;
display:flex!important;
margin:0;
border:0;
color:#FFF;
align-items: center;
background-size: cover;
background-position: center center;
height: 100%;
}
.CardImage{
height: 180px;
marginLeft: 113px;
paddingLeft: 56.25%;
paddingTop: 56.25%;
marginTop: 10px;
width: 10px;
}
.Images{
width: 150px;
height: 150px;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
Expand Down
36 changes: 15 additions & 21 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import logo from './logo.svg';
import {NavBar} from "./core/navbar/navbar";
import './App.css';
import {Routes} from "./core/routes/routes";
import {BrowserRouter as Router} from "react-router-dom";
import {Provider} from 'react-redux'
import {configureStore} from "./core/store/store"

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
const store = configureStore()


const App = () =>
<Provider store={store}>
<Router>
<NavBar />
<Routes />
</Router>
</Provider>

export default App;
2 changes: 2 additions & 0 deletions src/core/history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import {createBrowserHistory as history} from 'history'
export default history();
Binary file added src/core/images/background.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/core/images/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/core/images/brothImg.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/core/images/burgerImg.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/core/images/crazySandwich.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/core/images/desertImg.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/core/images/fancySandiwch.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/core/images/funnySandwich.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/core/images/pizzaImg.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/core/images/sandwichImg.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/core/images/sodaImg.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/core/images/uglySandwich.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/core/navbar/hooks/use-routes-on-click.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import history from "../../../core/history"

export const useRoutesOnClick = link =>{
return () =>{
history.push(link)
}
}
10 changes: 10 additions & 0 deletions src/core/navbar/navbar-icons/navbar-icons.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {IconButton} from "@material-ui/core";
import {useRoutesOnClick} from "../hooks/use-routes-on-click";

export const NavbarIcons = ({link, icon, edge = 'start'}) => {
const onClick = useRoutesOnClick(link);

return <IconButton onClick={onClick} edge={edge} aria-label='menu'>
{icon}
</IconButton>
}
17 changes: 17 additions & 0 deletions src/core/navbar/navbar-shopping-cart/navbar-shopping-cart.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {Badge, IconButton} from "@material-ui/core";
import {useRoutesOnClick} from "../hooks/use-routes-on-click";
import React from "react";
import {useSelector} from "react-redux";

export const NavbarShoppingCart = ({link, icon, edge = 'start'}) => {
const onClick = useRoutesOnClick(link);
const shoppingCartData = useSelector(selector)

return <IconButton onClick={onClick} edge={edge} aria-label='menu'>
<Badge badgeContent={shoppingCartData ? shoppingCartData.length : 0} color='secondary'>
{icon}
</Badge>
</IconButton>
}

const selector = ({shoppingCartReducer}) => shoppingCartReducer.items
5 changes: 5 additions & 0 deletions src/core/navbar/navbar-title/navbar-title.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Typography} from "@material-ui/core";

export const NavbarTitle = ({text}) =><Typography variant='h6' color='inherit'>
{text}
</Typography>
17 changes: 17 additions & 0 deletions src/core/navbar/navbar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {AppBar, Toolbar} from '@material-ui/core'
import HomeIcon from '@material-ui/icons/Home'
import {RestaurantMenu} from "@material-ui/icons";
import {NavbarIcons} from "./navbar-icons/navbar-icons";
import {NavbarTitle} from "./navbar-title/navbar-title";
import AddShoppingCartIcon from '@material-ui/icons/AddShoppingCart';
import {NavbarShoppingCart} from "./navbar-shopping-cart/navbar-shopping-cart";

export const NavBar = () =>
<AppBar position ='static'>
<Toolbar variant ='dense'>
<NavbarIcons link={'/'} icon={<HomeIcon/>} />
<NavbarIcons link={'/menu'} icon={<RestaurantMenu/>} />
<NavbarTitle text={'React Restaurant'} />
<NavbarShoppingCart link={'/menu/shopping-cart'} icon={<AddShoppingCartIcon/>} edge={'end'} />
</Toolbar>
</AppBar>
16 changes: 16 additions & 0 deletions src/core/routes/routes.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Router, Route, Switch} from "react-router-dom";
import {Home} from "../../home/home";
import {FoodMenu} from "../../menu/containers";
import history from '.././history';
import {SandwichMenu} from "../../sandwich-menu/containers";
import {ShoppingCart} from "../../shopping-cart/containers";

export const Routes = () =>
<Router history={history}>
<Switch>
<Route path={'/'} component={Home} exact/>
<Route path={'/menu'} component={FoodMenu} exact/>
<Route path={'/menu/sandwiches'} component={SandwichMenu}/>
<Route path={'/menu/shopping-cart'} component={ShoppingCart} />
</Switch>
</Router>
5 changes: 5 additions & 0 deletions src/core/site-error/error.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Box} from "@material-ui/core";

export const Error = () => <Box mt={12} ml={90}>
<div>The site has ran into an error. Please try again shortly</div>
</Box>
11 changes: 11 additions & 0 deletions src/core/store/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {createStore, applyMiddleware} from "redux";
import {rootReducers} from "../../startup/reducers/index";
import {createEpicMiddleware} from 'redux-observable'
import {rootEpic} from "../../startup/epics";

export const configureStore = () => {
const epicMiddleWare = createEpicMiddleware();
const store = createStore(rootReducers, applyMiddleware(epicMiddleWare));
epicMiddleWare.run(rootEpic)
return store;
}
15 changes: 15 additions & 0 deletions src/home/home.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import logo from '../logo.svg'
import {Link} from "react-router-dom";

export const Home = () =>
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Welcome to React Restaurant
</p>
<Link className="App-link" to="/menu">
Go to menu
</Link>
</header>
</div>
8 changes: 8 additions & 0 deletions src/menu/components/menu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import background from '../../core/images/background.jpg'
import {FoodCards} from "../containers/food-cards/food-cards";


export const Menu = () =>
<div className={'fullPage'} style={{backgroundImage: `url(${background}`}}>
<FoodCards />
</div>
3 changes: 3 additions & 0 deletions src/menu/containers/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {createContext} from "react";

export const MenuContext = createContext({})
5 changes: 5 additions & 0 deletions src/menu/containers/food-card/body/food-card-body.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Typography} from "@material-ui/core";

export const FoodCardBody = ({foodItem}) =><Typography variant='body2' color='textPrimary' component='p'>
{foodItem.description}
</Typography>
19 changes: 19 additions & 0 deletions src/menu/containers/food-card/food-card.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Card, CardActionArea, CardContent, CardMedia} from "@material-ui/core";
import history from "../../../core/history";
import {FoodCardTitle} from "./title/food-card-title";
import {FoodCardBody} from "./body/food-card-body";

export const FoodCard = ({foodItem}) => <Card>
<CardActionArea onClick={() => history.push(`menu/${foodItem.path}`)}>
<CardMedia component='img'
alt={foodItem.alt}
height='140'
image={foodItem.img}
title={foodItem.name}
className={'CardImage'}/>
</CardActionArea>
<CardContent>
<FoodCardTitle foodItem={foodItem}/>
<FoodCardBody foodItem={foodItem} />
</CardContent>
</Card>
5 changes: 5 additions & 0 deletions src/menu/containers/food-card/title/food-card-title.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Typography} from "@material-ui/core";

export const FoodCardTitle = ({foodItem}) =><Typography gutterBottom variant='h5' component='h2'>
{foodItem.name}
</Typography>
13 changes: 13 additions & 0 deletions src/menu/containers/food-cards/food-cards.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Box, Grid} from "@material-ui/core";
import {useMenuContext} from "../hooks/use-menu-context";
import {FoodCard} from "../food-card/food-card";

export const FoodCards = () =><Box mr={5} mb={2} ml={5}>
<Grid container direction='row' justify='space-around' spacing={8}>
{useMenuContext().data.map(foodItem =>
<Grid item xs={12} sm={12} md={12} lg={3} key={foodItem.id}>
<FoodCard foodItem={foodItem} />
</Grid>
)}
</Grid>
</Box>
6 changes: 6 additions & 0 deletions src/menu/containers/hooks/use-defaul-menu-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {useState} from "react";

export const useDefaultMenuContext = () => {
const [data, setData] = useState([])
return {data, setData}
}
8 changes: 8 additions & 0 deletions src/menu/containers/hooks/use-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {useMenuContext} from "./use-menu-context";
import {foodData} from '../../data/food'
import {useEffect} from "react";

export const useInit = () => {
const {setData} = useMenuContext()
useEffect(() => setData(() => foodData),[])
}
4 changes: 4 additions & 0 deletions src/menu/containers/hooks/use-menu-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {useContext} from "react";
import {MenuContext} from "../context";

export const useMenuContext = () => useContext(MenuContext)
10 changes: 10 additions & 0 deletions src/menu/containers/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {MenuContext} from "./context";
import {useDefaultMenuContext} from "./hooks/use-defaul-menu-context";
import {InitBehaviour} from "./init-behaviour";
import {Menu} from "../components/menu";

export const FoodMenu = () =>
<MenuContext.Provider value={useDefaultMenuContext()}>
<InitBehaviour />
<Menu/>
</MenuContext.Provider>
6 changes: 6 additions & 0 deletions src/menu/containers/init-behaviour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {useInit} from "./hooks/use-init";

export const InitBehaviour = () => {
useInit()
return ''
}
Loading