Dish cards
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -1366,6 +1366,14 @@
|
|||||||
"react-transition-group": "^4.4.0"
|
"react-transition-group": "^4.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@material-ui/icons": {
|
||||||
|
"version": "4.9.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@material-ui/icons/-/icons-4.9.1.tgz",
|
||||||
|
"integrity": "sha512-GBitL3oBWO0hzBhvA9KxqcowRUsA0qzwKkURyC8nppnC3fw54KPKZ+d4V1Eeg/UnDRSzDaI9nGCdel/eh9AQMg==",
|
||||||
|
"requires": {
|
||||||
|
"@babel/runtime": "^7.4.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@material-ui/lab": {
|
"@material-ui/lab": {
|
||||||
"version": "4.0.0-alpha.56",
|
"version": "4.0.0-alpha.56",
|
||||||
"resolved": "https://registry.npmjs.org/@material-ui/lab/-/lab-4.0.0-alpha.56.tgz",
|
"resolved": "https://registry.npmjs.org/@material-ui/lab/-/lab-4.0.0-alpha.56.tgz",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@material-ui/core": "^4.11.0",
|
"@material-ui/core": "^4.11.0",
|
||||||
|
"@material-ui/icons": "^4.9.1",
|
||||||
"@material-ui/lab": "^4.0.0-alpha.56",
|
"@material-ui/lab": "^4.0.0-alpha.56",
|
||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@testing-library/jest-dom": "^4.2.4",
|
||||||
"@testing-library/react": "^9.5.0",
|
"@testing-library/react": "^9.5.0",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
@import "./styles/SearchResults.scss";
|
@import "./styles/SearchResults.scss";
|
||||||
@import "./styles/Pictograms.scss";
|
@import "./styles/Pictograms.scss";
|
||||||
@import "./styles/Restaurant.scss";
|
@import "./styles/Restaurant.scss";
|
||||||
|
@import "./styles/DishList.scss";
|
||||||
|
|
||||||
.App {
|
.App {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
$main-color: #eb9800;
|
$main-color: #eb9800;
|
||||||
$secondary-color: #307482;
|
$secondary-color: #307482;
|
||||||
$darker-color: #234f53;
|
$darker-color: #234f53;
|
||||||
$bg-color: #ffffff;
|
$bg-color: #f8f8f8;
|
||||||
$accents-color: #0e8496;
|
$accents-color: #0e8496;
|
||||||
$lighter-color: #00d1b5;
|
$lighter-color: #00d1b5;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import * as toggles from "./toggles";
|
||||||
|
|
||||||
const autocomplete = (input) => {
|
const autocomplete = (input) => {
|
||||||
return {
|
return {
|
||||||
@@ -82,6 +83,7 @@ export const fetchRestaurant = (id) => {
|
|||||||
.get("http://localhost:4000/restaurant?restaurantId=" + id)
|
.get("http://localhost:4000/restaurant?restaurantId=" + id)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch(setRestaurant(response.data));
|
dispatch(setRestaurant(response.data));
|
||||||
|
dispatch(toggles.hideDishes());
|
||||||
dispatch(setAppMode("APP_RESTAURANT"));
|
dispatch(setAppMode("APP_RESTAURANT"));
|
||||||
dispatch(fetchAllDishes(id));
|
dispatch(fetchAllDishes(id));
|
||||||
})
|
})
|
||||||
@@ -102,6 +104,7 @@ export const fetchAllDishes = (id) => {
|
|||||||
.get("http://localhost:4000/restaurant/dishes?restaurantId=" + id)
|
.get("http://localhost:4000/restaurant/dishes?restaurantId=" + id)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch(setDishes(response.data));
|
dispatch(setDishes(response.data));
|
||||||
|
dispatch(toggles.showDishes());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
11
src/actions/toggles.js
Normal file
11
src/actions/toggles.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
export const showDishes = () => {
|
||||||
|
return {
|
||||||
|
type: "SET_DISHLIST_VISIBLE",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const hideDishes = () => {
|
||||||
|
return {
|
||||||
|
type: "SET_DISHLIST_HIDDEN",
|
||||||
|
};
|
||||||
|
};
|
||||||
20
src/components/CardDish.js
Normal file
20
src/components/CardDish.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
export default function CardDish(props) {
|
||||||
|
const { name, price, imgUrl } = props.dish;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="carddish-container">
|
||||||
|
<div className="carddish-left">
|
||||||
|
<div
|
||||||
|
className="carddish-img"
|
||||||
|
style={{ backgroundImage: "url(" + imgUrl + ")" }}
|
||||||
|
/>
|
||||||
|
<h2>{name}</h2>
|
||||||
|
</div>
|
||||||
|
<div className="carddish-right">
|
||||||
|
<h5>{price}</h5>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
40
src/components/DishList.js
Normal file
40
src/components/DishList.js
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import React from "react";
|
||||||
|
import DishesCategory from "./DishesCategory";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
|
function extractCategories(dishes) {
|
||||||
|
var categories = new Set();
|
||||||
|
|
||||||
|
if (typeof dishes !== "undefined" && dishes.length > 0) {
|
||||||
|
dishes.map((dish) => categories.add(dish.category));
|
||||||
|
return Array.from(categories);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterDishes(dishes, category) {
|
||||||
|
var result = [];
|
||||||
|
|
||||||
|
dishes.map((dish) => {
|
||||||
|
if (dish.category === category) {
|
||||||
|
result.push(dish);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DishList(props) {
|
||||||
|
const dishlist = useSelector((state) => state.dishes);
|
||||||
|
const categoriesArray = extractCategories(dishlist);
|
||||||
|
const categories = categoriesArray.map((category) => {
|
||||||
|
return (
|
||||||
|
<DishesCategory
|
||||||
|
key={category}
|
||||||
|
name={category}
|
||||||
|
dishes={filterDishes(dishlist, category)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return <div className="dishlist-container">{categories}</div>;
|
||||||
|
}
|
||||||
27
src/components/DishesCategory.js
Normal file
27
src/components/DishesCategory.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import React from "react";
|
||||||
|
import Accordion from "@material-ui/core/Accordion";
|
||||||
|
import AccordionSummary from "@material-ui/core/AccordionSummary";
|
||||||
|
import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
|
||||||
|
import List from "@material-ui/core/List";
|
||||||
|
import ListItem from "@material-ui/core/ListItem";
|
||||||
|
import CardDish from "./CardDish";
|
||||||
|
|
||||||
|
export default function DishesCategory(props) {
|
||||||
|
const dishes = props.dishes;
|
||||||
|
const dishCards = dishes.map((dish) => {
|
||||||
|
return (
|
||||||
|
<ListItem key={dish._id}>
|
||||||
|
<CardDish dish={dish}></CardDish>
|
||||||
|
</ListItem>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Accordion>
|
||||||
|
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
||||||
|
<h4>{props.name}</h4>
|
||||||
|
</AccordionSummary>
|
||||||
|
<List>{dishCards}</List>
|
||||||
|
</Accordion>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import Pictograms from "./Pictograms";
|
import Pictograms from "./Pictograms";
|
||||||
|
import DishList from "./DishList";
|
||||||
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function Restaurant(props) {
|
export default function Restaurant(props) {
|
||||||
const restaurant = useSelector((state) => state.restaurant);
|
const restaurant = useSelector((state) => state.restaurant);
|
||||||
|
const showDishList = useSelector((state) => state.toggles.showDishList);
|
||||||
function extractTags(tags) {
|
function extractTags(tags) {
|
||||||
var results = [];
|
var results = [];
|
||||||
for (let [key, value] of Object.entries(tags)) {
|
for (let [key, value] of Object.entries(tags)) {
|
||||||
@@ -26,7 +29,10 @@ export default function Restaurant(props) {
|
|||||||
</div>
|
</div>
|
||||||
<h1>{restaurant.name}</h1>
|
<h1>{restaurant.name}</h1>
|
||||||
<p>{restaurant.city}</p>
|
<p>{restaurant.city}</p>
|
||||||
<hr />
|
<div className="restaurant-dishes">
|
||||||
|
{showDishList === false && <CircularProgress />}
|
||||||
|
{showDishList === true && <DishList />}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import appMode from "./appMode";
|
|||||||
import searchQuery from "./searchQuery";
|
import searchQuery from "./searchQuery";
|
||||||
import restaurant from "./restaurant";
|
import restaurant from "./restaurant";
|
||||||
import dishes from "./dishes";
|
import dishes from "./dishes";
|
||||||
|
import toggles from "./toggles";
|
||||||
|
|
||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
autocomplete: autoCompleteReducer,
|
autocomplete: autoCompleteReducer,
|
||||||
@@ -13,6 +14,7 @@ const rootReducer = combineReducers({
|
|||||||
searchQuery: searchQuery,
|
searchQuery: searchQuery,
|
||||||
restaurant: restaurant,
|
restaurant: restaurant,
|
||||||
dishes: dishes,
|
dishes: dishes,
|
||||||
|
toggles: toggles,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default rootReducer;
|
export default rootReducer;
|
||||||
|
|||||||
16
src/reducers/toggles.js
Normal file
16
src/reducers/toggles.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const initialState = {
|
||||||
|
showDishList: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggles = (state = initialState, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case "SET_DISHLIST_VISIBLE":
|
||||||
|
return (state = { ...state, showDishList: true });
|
||||||
|
case "SET_DISHLIST_HIDDEN":
|
||||||
|
return (state = { ...state, showDishList: false });
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default toggles;
|
||||||
29
src/styles/DishList.scss
Normal file
29
src/styles/DishList.scss
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
.dishlist-container {
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.carddish-container {
|
||||||
|
margin-top: 20px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-weight: 300;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.carddish-img {
|
||||||
|
background-color: $secondary-color;
|
||||||
|
width: 150px;
|
||||||
|
height: 150px;
|
||||||
|
border-radius: 75px;
|
||||||
|
margin: 0px 20px 0px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.carddish-left {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
.restaurant-container {
|
.restaurant-container {
|
||||||
min-width: 100vw;
|
min-width: 100vw;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-flow: column;
|
||||||
|
align-items: center;
|
||||||
h1 {
|
h1 {
|
||||||
font-weight: 100;
|
font-weight: 100;
|
||||||
font-size: 3rem;
|
font-size: 3rem;
|
||||||
@@ -34,3 +37,7 @@
|
|||||||
margin: 8px;
|
margin: 8px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.restaurant-dishes {
|
||||||
|
min-width: 70%;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user