From 8a1149d22328ff3b20fe6a7b4b97504576918582 Mon Sep 17 00:00:00 2001 From: MrFry Date: Sun, 8 Mar 2020 12:16:14 +0100 Subject: [PATCH] Added tabs.json --- src/components/layout.js | 32 ++++++++++++-------------------- src/data/tabs.json | 18 ++++++++++++++++++ src/pages/allQuestions.js | 7 ++----- src/pages/feedback.js | 16 +++++----------- src/pages/userQuestions.js | 6 ++---- 5 files changed, 39 insertions(+), 40 deletions(-) create mode 100644 src/data/tabs.json diff --git a/src/components/layout.js b/src/components/layout.js index ab5faaa..e538615 100644 --- a/src/components/layout.js +++ b/src/components/layout.js @@ -1,5 +1,7 @@ import Link from 'next/link' +import tabs from '../data/tabs.json' + // TODO: activelink prop to set link to active export default function Layout (props) { const { currPageName } = props @@ -17,26 +19,16 @@ export default function Layout (props) { Frylabs - - home - - - manual - - - AllQuestions - - - userQuestions - + {Object.keys(tabs).map((key) => { + const item = tabs[key] + return ( + + {item.text} + + ) + })}
{props.children} diff --git a/src/data/tabs.json b/src/data/tabs.json new file mode 100644 index 0000000..f29d916 --- /dev/null +++ b/src/data/tabs.json @@ -0,0 +1,18 @@ +{ + "index": { + "href": "/", + "text": "Home" + }, + "manual": { + "href": "/manual", + "text": "Manual" + }, + "allQuestions": { + "href": "/allQuestions", + "text": "All question" + }, + "userQuestions": { + "href": "/userQuestions", + "text": "User Questions" + } +} diff --git a/src/pages/allQuestions.js b/src/pages/allQuestions.js index 4245e58..89e4126 100644 --- a/src/pages/allQuestions.js +++ b/src/pages/allQuestions.js @@ -10,11 +10,9 @@ import constants from '../constants.json' export default function AllQuestions (props) { const [data, setData] = useState(null) - const [loaded, setLoaded] = useState(false) const [activeSubjName, setActiveSubjName] = useState('') const [searchTerm, setSearchTerm] = useState('') - // TODO: fetches twice useEffect(() => { console.info('Fetching data') fetch(`${constants.serverUrl}data.json`) @@ -23,11 +21,10 @@ export default function AllQuestions (props) { }) .then((data) => { setData(data) - setLoaded(true) }) - }, [loaded]) + }, []) - if (loaded) { + if (data) { let currSubj = data.Subjects.find((subj) => { return subj.Name === activeSubjName }) diff --git a/src/pages/feedback.js b/src/pages/feedback.js index 31da9cd..5056313 100644 --- a/src/pages/feedback.js +++ b/src/pages/feedback.js @@ -1,13 +1,7 @@ -import React, { PureComponent } from 'react' - -class Feedback extends PureComponent { - render () { - return ( -
+export default function Feedback (props) { + return ( +
hello Feedback -
- ) - } +
+ ) } - -export default Feedback diff --git a/src/pages/userQuestions.js b/src/pages/userQuestions.js index 03247ba..1bb2550 100644 --- a/src/pages/userQuestions.js +++ b/src/pages/userQuestions.js @@ -6,7 +6,6 @@ import Layout from '../components/layout' import constants from '../constants.json' export default function UserQuestions (props) { - const [loaded, setLoaded] = useState(false) const [qa, setQa] = useState(null) useEffect(() => { @@ -17,11 +16,10 @@ export default function UserQuestions (props) { }) .then((data) => { setQa(data) - setLoaded(true) }) - }, [loaded]) + }, []) - if (loaded) { + if (qa) { let questions = Object.keys(qa).map((key, i) => { let q = qa[key] return (