From 3d8f398e89935e52e4214e420be7b9e0f4442def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Kl=C3=BCter?= Date: Sat, 10 Apr 2021 13:40:43 +0200 Subject: [PATCH] Updated our menu-itmes to navigate withROuter HOC --- package-lock.json | 96 +++++++++++++++++ package.json | 1 + src/App.jsx | 7 +- .../directory/directory.component.jsx | 102 +++++++++--------- .../menu-item/menu-item.component.jsx | 34 +++--- src/index.js | 5 +- 6 files changed, 175 insertions(+), 70 deletions(-) diff --git a/package-lock.json b/package-lock.json index 925b963..449bc0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7296,6 +7296,19 @@ "resolved": "https://registry.npmjs.org/hex-color-regex/-/hex-color-regex-1.1.0.tgz", "integrity": "sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==" }, + "history": { + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz", + "integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==", + "requires": { + "@babel/runtime": "^7.1.2", + "loose-envify": "^1.2.0", + "resolve-pathname": "^3.0.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0", + "value-equal": "^1.0.1" + } + }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -7306,6 +7319,14 @@ "minimalistic-crypto-utils": "^1.0.1" } }, + "hoist-non-react-statics": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", + "integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==", + "requires": { + "react-is": "^16.7.0" + } + }, "hoopy": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/hoopy/-/hoopy-0.1.4.tgz", @@ -10338,6 +10359,15 @@ "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==" }, + "mini-create-react-context": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/mini-create-react-context/-/mini-create-react-context-0.4.1.tgz", + "integrity": "sha512-YWCYEmd5CQeHGSAKrYvXgmzzkrvssZcuuQDDeqkT+PziKGMgE+0MCCtcKbROzocGBG1meBLl2FotlRwf4gAzbQ==", + "requires": { + "@babel/runtime": "^7.12.1", + "tiny-warning": "^1.0.3" + } + }, "mini-css-extract-plugin": { "version": "0.11.3", "resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-0.11.3.tgz", @@ -12935,6 +12965,52 @@ "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.8.3.tgz", "integrity": "sha512-X8jZHc7nCMjaCqoU+V2I0cOhNW+QMBwSUkeXnTi8IPe6zaRWfn60ZzvFDZqWPfmSJfjub7dDW1SP0jaHWLu/hg==" }, + "react-router": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-5.2.0.tgz", + "integrity": "sha512-smz1DUuFHRKdcJC0jobGo8cVbhO3x50tCL4icacOlcwDOEQPq4TMqwx3sY1TP+DvtTgz4nm3thuo7A+BK2U0Dw==", + "requires": { + "@babel/runtime": "^7.1.2", + "history": "^4.9.0", + "hoist-non-react-statics": "^3.1.0", + "loose-envify": "^1.3.1", + "mini-create-react-context": "^0.4.0", + "path-to-regexp": "^1.7.0", + "prop-types": "^15.6.2", + "react-is": "^16.6.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "path-to-regexp": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", + "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "requires": { + "isarray": "0.0.1" + } + } + } + }, + "react-router-dom": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-5.2.0.tgz", + "integrity": "sha512-gxAmfylo2QUjcwxI63RhQ5G85Qqt4voZpUXSEqCwykV0baaOTQDR1f0PmY8AELqIyVc0NEZUj0Gov5lNGcXgsA==", + "requires": { + "@babel/runtime": "^7.1.2", + "history": "^4.9.0", + "loose-envify": "^1.3.1", + "prop-types": "^15.6.2", + "react-router": "5.2.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0" + } + }, "react-scripts": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-4.0.3.tgz", @@ -13379,6 +13455,11 @@ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==" }, + "resolve-pathname": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-3.0.0.tgz", + "integrity": "sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==" + }, "resolve-url": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", @@ -15210,6 +15291,16 @@ "resolved": "https://registry.npmjs.org/timsort/-/timsort-0.3.0.tgz", "integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=" }, + "tiny-invariant": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.1.0.tgz", + "integrity": "sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw==" + }, + "tiny-warning": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz", + "integrity": "sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA==" + }, "tmpl": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", @@ -15696,6 +15787,11 @@ "spdx-expression-parse": "^3.0.0" } }, + "value-equal": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/value-equal/-/value-equal-1.0.1.tgz", + "integrity": "sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 05730ef..a854e14 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "node-sass": "^5.0.0", "react": "^17.0.2", "react-dom": "^17.0.2", + "react-router-dom": "^5.2.0", "react-scripts": "4.0.3", "web-vitals": "^0.2.4", "workbox-background-sync": "^5.1.4", diff --git a/src/App.jsx b/src/App.jsx index cf3a4d6..1c0cc1e 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,14 +1,17 @@ import React from 'react'; +import { Switch, Route } from 'react-router-dom'; import './App.css'; import HomePage from './pages/homepage/hompage.component' + function App() { return (
- + + +
); } export default App; - \ No newline at end of file diff --git a/src/components/directory/directory.component.jsx b/src/components/directory/directory.component.jsx index 32f2c48..128298b 100644 --- a/src/components/directory/directory.component.jsx +++ b/src/components/directory/directory.component.jsx @@ -1,58 +1,58 @@ import React from 'react'; -import MenuItem from '../menu-item/menu-item.component' -import './directory.styles.scss' +import MenuItem from '../menu-item/menu-item.component'; +import './directory.styles.scss'; class Directory extends React.Component { - constructor() { - super(); + constructor() { + super(); - this.state = { - sections: [{ - title: 'hats', - imageUrl: 'https://i.ibb.co/cvpntL1/hats.png', - id: 1, - linkUrl: 'shop/hats' - }, - { - title: 'jackets', - imageUrl: 'https://i.ibb.co/px2tCc3/jackets.png', - id: 2, - linkUrl: 'shop/jackets' - }, - { - title: 'sneakers', - imageUrl: 'https://i.ibb.co/0jqHpnp/sneakers.png', - id: 3, - linkUrl: 'shop/sneakers' - }, - { - title: 'womens', - imageUrl: 'https://i.ibb.co/GCCdy8t/womens.png', - size: 'large', - id: 4, - linkUrl: 'shop/womens' - }, - { - title: 'mens', - imageUrl: 'https://i.ibb.co/R70vBrQ/men.png', - size: 'large', - id: 5, - linkUrl: 'shop/mens' - }] - } - } - render() { - return ( -
- { - this.state.sections.map(({ title, imageUrl, id, size }) => ( - - )) - } -
- ); - } + this.state = { + sections: [ + { + title: 'hats', + imageUrl: 'https://i.ibb.co/cvpntL1/hats.png', + id: 1, + linkUrl: 'shop/hats', + }, + { + title: 'jackets', + imageUrl: 'https://i.ibb.co/px2tCc3/jackets.png', + id: 2, + linkUrl: 'shop/jackets', + }, + { + title: 'sneakers', + imageUrl: 'https://i.ibb.co/0jqHpnp/sneakers.png', + id: 3, + linkUrl: 'shop/sneakers', + }, + { + title: 'womens', + imageUrl: 'https://i.ibb.co/GCCdy8t/womens.png', + size: 'large', + id: 4, + linkUrl: 'shop/womens', + }, + { + title: 'mens', + imageUrl: 'https://i.ibb.co/R70vBrQ/men.png', + size: 'large', + id: 5, + linkUrl: 'shop/mens', + }, + ], + }; + } + render() { + return ( +
+ {this.state.sections.map(({ id, ...otherSectionPRops }) => ( + + ))} +
+ ); + } } -export default Directory; \ No newline at end of file +export default Directory; diff --git a/src/components/menu-item/menu-item.component.jsx b/src/components/menu-item/menu-item.component.jsx index 0215880..396ebdf 100644 --- a/src/components/menu-item/menu-item.component.jsx +++ b/src/components/menu-item/menu-item.component.jsx @@ -1,22 +1,24 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; -import './menu-item.styles.scss' +import './menu-item.styles.scss'; -const MenuItem = ({ title, imageUrl, size }) => ( +const MenuItem = ({ title, imageUrl, size, history, linkUrl, match }) => ( +
history.push(`${match.url}${linkUrl}`)} + >
-
-
-

{title.toUpperCase()}

- SHOP NOW -
+ className='background-image' + style={{ + backgroundImage: `url(${imageUrl})`, + }} + /> +
+

{title.toUpperCase()}

+ SHOP NOW
-) +
+); -export default MenuItem; \ No newline at end of file +export default withRouter(MenuItem); diff --git a/src/index.js b/src/index.js index c15f402..30ab8d7 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,14 @@ import React from 'react'; import ReactDOM from 'react-dom'; +import { BrowserRouter } from 'react-router-dom'; import './index.css'; import App from './App'; ReactDOM.render( - + + + , document.getElementById('root') ); \ No newline at end of file