Skip to content

Commit dc37152

Browse files
updated menu page
1 parent cceb1fc commit dc37152

19 files changed

+593
-536
lines changed

src/App.js

Lines changed: 114 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,118 @@
11
import React from "react";
22
import { Route, Routes, BrowserRouter } from "react-router-dom";
33
//Componnets
4-
import HeaderNav from "./components/HeaderNav.tsx";
5-
import FooterNav from "./components/FooterNav.tsx";
4+
import HeaderNav from "./components/HeaderNav.js";
5+
import FooterNav from "./components/FooterNav.js";
66
import MenuRoot from "./components/MenuRoot";
77
import RootSection from "./components/RootSection";
88
import ContactRoot from "./components/ContactRoot";
9-
import SushiRoot from "./components/SushiRoot";
10-
import SaleRoot from "./components/SaleRoot";
11-
import PastaRoot from "./components/PastaRoot";
12-
import DrinksRoot from "./components/DrinksRoot";
9+
// import SushiRoot from "./components/SushiRoot";
10+
// import SaleRoot from "./components/SaleRoot";
11+
// import PastaRoot from "./components/PastaRoot";
12+
// import DrinksRoot from "./components/DrinksRoot";
1313
import AboutUs from "./components/AboutUs";
1414
import Blog from "./components/Blog";
1515
import Cart from "./components/Cart";
1616
import PasswordRecovery from "./components/PasswordRecovery.js";
1717
import Register from "./components/Register";
1818
//Data
19-
import { allProducts } from "./data/AllProducts";
19+
import { allProductsData } from "./data/AllProductsData.js";
20+
import { AllCategories } from "./data/AllCategories";
2021
export default class App extends React.Component {
2122
constructor() {
2223
super();
2324
this.state = {
25+
allCategories: [],
26+
activeCategory: "Menu",
2427
cartItems: [],
28+
allProducts: [],
2529
};
30+
this.getProductsByCategory = this.getProductsByCategory.bind(this);
31+
this.changeCategory = this.changeCategory.bind(this);
2632
}
33+
34+
// GET DATA
35+
/*******************************************************/
36+
allCategoriesData = new Promise((resolve, reject) => {
37+
if (true) {
38+
resolve(AllCategories);
39+
return;
40+
}
41+
reject("error, check the code!");
42+
});
43+
allProductsData = new Promise((resolve, reject) => {
44+
if (true) {
45+
resolve(allProductsData);
46+
return;
47+
}
48+
reject("error, check the code!");
49+
});
50+
51+
getCategories = async () => {
52+
try {
53+
const result = await this.allCategoriesData;
54+
this.setState({ allCategories: result });
55+
} catch (error) {
56+
console.log(error);
57+
}
58+
};
59+
60+
getAllProducts = async () => {
61+
try {
62+
const result = await this.allProductsData;
63+
this.setState({ allProducts: result });
64+
} catch (error) {
65+
console.log(error);
66+
}
67+
};
68+
69+
// HANDLE CHANGE
70+
/*******************************************************/
71+
changeCategory = async (newCategory) => {
72+
this.setState({ activeCategory: newCategory });
73+
this.getProductsByCategory(newCategory);
74+
};
75+
76+
getProductsByCategory = async (category) => {
77+
let separateCategoriesByname = [];
78+
//Separate arrays by category names
79+
const separateCategories = allProductsData.reduce(function (
80+
singleCategory,
81+
singleItem
82+
) {
83+
separateCategoriesByname = Object.keys(singleCategory);
84+
85+
if (!singleCategory[singleItem.Category])
86+
singleCategory[singleItem.Category] = singleItem;
87+
else
88+
singleCategory[singleItem.Category] = Array.isArray(
89+
singleCategory[singleItem.Category]
90+
)
91+
? singleCategory[singleItem.Category].concat(singleItem)
92+
: [singleCategory[singleItem.Category]].concat(singleItem);
93+
return singleCategory;
94+
},
95+
{});
96+
97+
const result = Object.keys(separateCategories).map(
98+
(e) => separateCategories[e]
99+
);
100+
101+
let singleCategoryArray = [];
102+
result.map((categories) => {
103+
singleCategoryArray = categories;
104+
});
105+
//Change products by category
106+
separateCategoriesByname.forEach((cate) => {
107+
if (cate === category) {
108+
this.setState({ allProducts: separateCategories[category] });
109+
}
110+
if (category === "Menu") {
111+
this.setState({ allProducts: allProductsData });
112+
}
113+
});
114+
};
115+
27116
CheckRepeatableProducts = (
28117
cartItems,
29118
targetProduct,
@@ -172,25 +261,37 @@ export default class App extends React.Component {
172261
}
173262
};
174263
componentDidMount() {
175-
console.log(allProducts)
264+
this.getCategories();
265+
this.getAllProducts();
266+
this.getProductsByCategory(this.state.activeCategory);
176267
}
177268
render() {
178-
console.log(this.state.cartItems);
269+
// console.log(this.state.cartItems);
179270
return (
180271
<BrowserRouter>
181272
<HeaderNav />
182-
<RootSection />
183273
<Routes>
184274
<Route path="/pizza-time-with-react" element={<RootSection />} />
185-
<Route path="/pizza" element={<MenuRoot />} />
275+
<Route
276+
path="/menu"
277+
element={
278+
<MenuRoot
279+
allProducts={this.state.allProducts}
280+
allCategories={this.state.allCategories}
281+
activeCategory={this.state.activeCategory}
282+
changeCategory={this.changeCategory}
283+
/>
284+
}
285+
/>
286+
{/* <Route path="/pizza" element={<MenuRoot />} /> */}
186287
<Route path="/contact" element={<ContactRoot />} />
187288
<Route path="/cart" element={<Cart />} />
188289
<Route path="/blog" element={<Blog />} />
189290
<Route path="/about" element={<AboutUs />} />
190-
<Route path="/sushi" element={<SushiRoot />} />
291+
{/* <Route path="/sushi" element={<SushiRoot />} />
191292
<Route path="/sale" element={<SaleRoot />} />
192293
<Route path="/pasta" element={<PastaRoot />} />
193-
<Route path="/drinks" element={<DrinksRoot />} />
294+
<Route path="/drinks" element={<DrinksRoot />} /> */}
194295
<Route path="/register" element={<Register />} />
195296
<Route path="/password-recovery" element={<PasswordRecovery />} />
196297
</Routes>

src/assets/MenuStyles.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ input[type="search"]::-webkit-search-results-decoration {
132132
overflow-x: auto;
133133
scroll-behavior: smooth;
134134
}
135+
136+
.side-menu ul a {
137+
color: var(--white);
138+
}
139+
.side-menu ul a:hover {
140+
color: var(--pizza-red)
141+
}
142+
135143
.pizza-section {
136144
display: grid;
137145
grid-column: span 1;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/components/PizzaRoot.js renamed to src/components/Drafts/PizzaRoot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import PizzaMenu from "./PizzaMenu";
3-
import ScrollBtn from "./ScrollBtn";
4-
import AddItemsToCart from "./AddItemsToCart";
3+
import ScrollBtn from "../ScrollBtn";
4+
import AddItemsToCart from "../AddItemsToCart";
55

66
export default class PizzaRoot extends React.Component {
77
render() {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/components/FooterNav.tsx renamed to src/components/FooterNav.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class FooterNav extends React.Component {
4242
}
4343
onClick={ResetLocation}
4444
className="txt-white"
45-
to="/pizza"
45+
to="/menu"
4646
>
4747
<>Menu</>
4848
</NavLink>
@@ -123,5 +123,3 @@ export default class FooterNav extends React.Component {
123123
);
124124
}
125125
}
126-
127-

src/components/HeaderNav.tsx renamed to src/components/HeaderNav.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default class NavBar extends React.Component {
7979
: {}
8080
}
8181
className="txt-white"
82-
to="/pizza"
82+
to="/menu"
8383
>
8484
<>Menu</>
8585
</NavLink>

src/components/MenuNavBar.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react";
2+
import { NavLink } from "react-router-dom";
3+
import SearchIcon from "../images/search-icon.png";
4+
5+
const ResetLocation = () => window.scrollTo(0, 0);
6+
7+
export default class MenuNavBar extends React.Component {
8+
ResetLocation = () => window.scrollTo(0, 0);
9+
render() {
10+
const { allCategories, changeCategory } = this.props;
11+
return (
12+
<>
13+
<article className="side-menu">
14+
<section className="menu-search-section">
15+
<input
16+
type="text"
17+
className="menu-search"
18+
placeholder="search..."
19+
></input>
20+
<img src={SearchIcon} alt="" className="menu-search-icon"></img>
21+
</section>
22+
<ul>
23+
{allCategories.map((category) => (
24+
<li>
25+
<NavLink
26+
key={category.name}
27+
to="/menu"
28+
onClick={() => {
29+
changeCategory(category.name);
30+
ResetLocation();
31+
}}
32+
>
33+
{category.name}
34+
</NavLink>
35+
</li>
36+
))}
37+
</ul>
38+
</article>
39+
</>
40+
);
41+
}
42+
}

src/components/MenuNavBar.tsx

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)