diff --git a/README.md b/README.md index 6ece4bf..0197832 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ You can test the website locally using `yarn start`.

Deployment

-You can the website to GitHub pages using `npm run deploy`. +You can deploy the website to GitHub pages using `npm run deploy`.

Contributing

diff --git a/package.json b/package.json index 2992e43..231aeb6 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "proptypes": "^1.1.0", "react": "^17.0.2", "react-dom": "^17.0.2", - "react-router-dom": "^6.2.1", + "react-router-dom": "^6.4.5", "react-scripts": "5.0.0", "react-transition-group": "^4.4.2" }, diff --git a/src/components/UserMessage.jsx b/src/components/UserMessage.jsx index 57032cc..9559023 100644 --- a/src/components/UserMessage.jsx +++ b/src/components/UserMessage.jsx @@ -1,25 +1,31 @@ import React, { useState, useEffect } from 'react'; +import { Link, useSearchParams } from 'react-router-dom'; import user from '../img/user-img.png'; import { UserResponseList } from './UserResponseList'; import urlToJSON from './utils/urlToJSON'; -import { Link } from 'react-router-dom'; import BackIcon from '../img/back.png'; +import createPathIdQuery from './utils/createPathIdQuery'; -export default function UserMessage({ setjsonPathMap, jsonPathMap, pathId }) { +export default function UserMessage({ setjsonPathMap, jsonPathMap }) { const [userName, setuserName] = useState('Test-User >'); + + const [searchParams] = useSearchParams(); + const pathId = searchParams.get('pathId'); + useEffect(() => { setjsonPathMap(urlToJSON(pathId)); - urlToJSON(pathId); setuserName('You'); }, [pathId, setjsonPathMap]); return (
{/* Back button link */} - {/* when pathId===undefined (i.e. First Message) --> Don't render back buttom. */} - {pathId !== undefined ? ( + {/* when pathId is falsy (i.e. First Message) --> Don't render back buttom. */} + {pathId ? ( back diff --git a/src/components/UserMessageSection.jsx b/src/components/UserMessageSection.jsx index c012c2d..1ae59d2 100644 --- a/src/components/UserMessageSection.jsx +++ b/src/components/UserMessageSection.jsx @@ -1,32 +1,34 @@ import React from 'react'; import PathMap from './PathMap'; -import { Routes, Route, HashRouter as Router } from 'react-router-dom'; +import { + Routes, + Route, + BrowserRouter as Router, + createBrowserRouter, + RouterProvider, + createRoutesFromElements, +} from 'react-router-dom'; import UserMessage from './UserMessage'; export function UserMessageSection({ setjsonPathMap, jsonPathMap }) { - return ( - - ( - - ( -
- setjsonPathMap(json)} - jsonPathMap={jsonPathMap} - /> -
- )} - /> - - -
- )} - /> -
+ const router = createBrowserRouter( + createRoutesFromElements( + <> + + + setjsonPathMap(json)} + jsonPathMap={jsonPathMap} + /> +
+ } + /> + + ) ); + + return ; } diff --git a/src/components/UserResponse.jsx b/src/components/UserResponse.jsx index bc133b7..89c547d 100644 --- a/src/components/UserResponse.jsx +++ b/src/components/UserResponse.jsx @@ -1,5 +1,6 @@ import React, { useState, useEffect } from 'react'; import { Link } from 'react-router-dom'; +import createPathIdQuery from './utils/createPathIdQuery'; //Each UserResponse export function UserResponse({ object, index, pathId }) { @@ -7,7 +8,7 @@ export function UserResponse({ object, index, pathId }) { const [url, setURL] = useState(''); useEffect(() => { - if (pathId === undefined) { + if (!pathId) { setURL(''); } else { setURL(pathId); @@ -24,12 +25,15 @@ export function UserResponse({ object, index, pathId }) { } to={ object.child !== undefined - ? url.toString() + 'u' + (Number(index) - 1).toString() + ? createPathIdQuery( + url.toString() + + 'u' + + (Number(index) - 1).toString()) : object.jump !== undefined - ? object.jump.toString() + ? createPathIdQuery(object.jump.toString()) : object.link === undefined ? '/' - : url.toString() + : createPathIdQuery(url.toString()) } onClick={() => { if (object.isGraph === true) { diff --git a/src/components/UserResponseList.jsx b/src/components/UserResponseList.jsx index 0214123..e0af00f 100644 --- a/src/components/UserResponseList.jsx +++ b/src/components/UserResponseList.jsx @@ -3,7 +3,11 @@ import { UserResponse } from './UserResponse'; import { useState, useEffect } from 'react'; //List of the User Responses in User Section -export function UserResponseList({ setjsonPathMap, jsonPathMap, pathId }) { +export function UserResponseList({ + setjsonPathMap, + jsonPathMap, + pathId, +}) { const [data, setData] = useState(jsonPathMap); useEffect(() => { diff --git a/src/components/utils/createPathIdQuery.js b/src/components/utils/createPathIdQuery.js new file mode 100644 index 0000000..6b54d3e --- /dev/null +++ b/src/components/utils/createPathIdQuery.js @@ -0,0 +1,5 @@ +import { PATH_ID_QUERY_PARAM } from '../../consts/URLConsts'; + +export default function createPathIdQuery(paramValue) { + return PATH_ID_QUERY_PARAM + paramValue; +} \ No newline at end of file diff --git a/src/components/utils/urlToJSON.jsx b/src/components/utils/urlToJSON.js similarity index 100% rename from src/components/utils/urlToJSON.jsx rename to src/components/utils/urlToJSON.js index 24e3adf..bb75b65 100644 --- a/src/components/utils/urlToJSON.jsx +++ b/src/components/utils/urlToJSON.js @@ -3,13 +3,13 @@ import data from '../../data/pathMap'; //Take pathId as a parameter and returns JSON data from pathMap. export default function urlToJSON(u) { //url format - u[position]-u[position] - var url = String(u).split('u'); var d = data; if (u === null || u === undefined) { return d; } + var url = String(u).split('u'); url.forEach((i, index) => { if (d === undefined || index > 100) { d = data; diff --git a/src/consts/URLConsts.js b/src/consts/URLConsts.js new file mode 100644 index 0000000..61ad23f --- /dev/null +++ b/src/consts/URLConsts.js @@ -0,0 +1 @@ +export const PATH_ID_QUERY_PARAM = '?pathId='; diff --git a/src/data/ContributionResources/Git.jsx b/src/data/ContributionResources/Git.jsx index a2b6e8c..b301ce1 100644 --- a/src/data/ContributionResources/Git.jsx +++ b/src/data/ContributionResources/Git.jsx @@ -1,22 +1,19 @@ -import ContributionResources from "."; - export default { - 'user-responses': [ - { - name: 'How to work with Git?', - link: 'http://learngitbranching.js.org/', - }, - { - name: 'How to work with forks?', - link: 'https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/working-with-forks' - }, - { - name: 'Done. What else should I know about?', - child: ContributionResources, - }, - ], - 'gooey-response': { - gooey: 'New to Git / GitHub? Check this out.', + 'user-responses': [ + { + name: 'How to work with Git?', + link: 'http://learngitbranching.js.org/', }, - }; - \ No newline at end of file + { + name: 'How to work with forks?', + link: 'https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/working-with-forks', + }, + { + name: 'Done. What else should I know about?', + jump: 'u0u2u0u0', + }, + ], + 'gooey-response': { + gooey: 'New to Git / GitHub? Check this out.', + }, +}; diff --git a/src/data/ContributionResources/index.jsx b/src/data/ContributionResources/index.jsx index 37f4df2..d22c2ea 100644 --- a/src/data/ContributionResources/index.jsx +++ b/src/data/ContributionResources/index.jsx @@ -1,7 +1,6 @@ -import Git from "./Git"; -import Conventions from "./Conventions"; -import Workspace from "./Workspace"; -import Contributor from "../Terasology/Contributor"; +import Git from './Git'; +import Conventions from './Conventions'; +import Workspace from './Workspace'; export default { 'user-responses': [ @@ -23,7 +22,7 @@ export default { }, { name: 'Which conventions should I follow?', - child: Conventions + child: Conventions, }, { name: 'Okay, got it. Now I feel ready to contribute!', diff --git a/src/data/pathMap.jsx b/src/data/pathMap.jsx index 681b89b..08841c9 100644 --- a/src/data/pathMap.jsx +++ b/src/data/pathMap.jsx @@ -22,7 +22,7 @@ export default { }, ], 'gooey-response': { - gooey: 'Which project you wish to explore? 🧐 ', + gooey: 'Which project do you wish to explore? 🧐 ', }, }, }, diff --git a/yarn.lock b/yarn.lock index ceb9cd4..8ee72d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1224,7 +1224,7 @@ core-js-pure "^3.20.2" regenerator-runtime "^0.13.4" -"@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.16.3", "@babel/runtime@^7.7.6", "@babel/runtime@^7.9.2": +"@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.16.3", "@babel/runtime@^7.9.2": version "7.17.2" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.17.2.tgz#66f68591605e59da47523c631416b18508779941" integrity sha512-hzeyJyMA1YGdJTuWU0e/j4wKXrU4OMFvY2MSlaI9B7VQb0r5cxTE3EAIS2Q7Tn2RIcDkRvTA/v2JsAEhxe99uw== @@ -1645,6 +1645,11 @@ schema-utils "^3.0.0" source-map "^0.7.3" +"@remix-run/router@1.0.5": + version "1.0.5" + resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.0.5.tgz#d5c65626add4c3c185a89aa5bd38b1e42daec075" + integrity sha512-my0Mycd+jruq/1lQuO5LBB6WTlL/e8DTCYWp44DfMTDcXz8DcTlgF0ISaLsGewt+ctHN+yA8xMq3q/N7uWJPug== + "@rollup/plugin-babel@^5.2.0": version "5.3.0" resolved "https://registry.yarnpkg.com/@rollup/plugin-babel/-/plugin-babel-5.3.0.tgz#9cb1c5146ddd6a4968ad96f209c50c62f92f9879" @@ -5243,13 +5248,6 @@ he@^1.2.0: resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== -history@^5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/history/-/history-5.2.0.tgz#7cdd31cf9bac3c5d31f09c231c9928fad0007b7c" - integrity sha512-uPSF6lAJb3nSePJ43hN3eKj1dTWpN9gMod0ZssbFTIsen+WehTmEadgL+kg78xLJFdRfrrC//SavDzmRVdE+Ig== - dependencies: - "@babel/runtime" "^7.7.6" - hoopy@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/hoopy/-/hoopy-0.1.4.tgz#609207d661100033a9a9402ad3dea677381c1b1d" @@ -8333,20 +8331,20 @@ react-refresh@^0.11.0: resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.11.0.tgz#77198b944733f0f1f1a90e791de4541f9f074046" integrity sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A== -react-router-dom@^6.2.1: - version "6.2.1" - resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.2.1.tgz#32ec81829152fbb8a7b045bf593a22eadf019bec" - integrity sha512-I6Zax+/TH/cZMDpj3/4Fl2eaNdcvoxxHoH1tYOREsQ22OKDYofGebrNm6CTPUcvLvZm63NL/vzCYdjf9CUhqmA== +react-router-dom@^6.4.5: + version "6.4.5" + resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.4.5.tgz#4fdb12efef4f3848c693a76afbeaed1f6ca02047" + integrity sha512-a7HsgikBR0wNfroBHcZUCd9+mLRqZS8R5U1Z1mzLWxFXEkUT3vR1XXmSIVoVpxVX8Bar0nQYYYc9Yipq8dWwAA== dependencies: - history "^5.2.0" - react-router "6.2.1" + "@remix-run/router" "1.0.5" + react-router "6.4.5" -react-router@6.2.1: - version "6.2.1" - resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.2.1.tgz#be2a97a6006ce1d9123c28934e604faef51448a3" - integrity sha512-2fG0udBtxou9lXtK97eJeET2ki5//UWfQSl1rlJ7quwe6jrktK9FCCc8dQb5QY6jAv3jua8bBQRhhDOM/kVRsg== +react-router@6.4.5: + version "6.4.5" + resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.4.5.tgz#73f382af2c8b9a86d74e761a7c5fc3ce7cb0024d" + integrity sha512-1RQJ8bM70YEumHIlNUYc6mFfUDoWa5EgPDenK/fq0bxD8DYpQUi/S6Zoft+9DBrh2xmtg92N5HMAJgGWDhKJ5Q== dependencies: - history "^5.2.0" + "@remix-run/router" "1.0.5" react-scripts@5.0.0: version "5.0.0"