From c1f019956a6a6b19cdcd83052edd1e5c31da4ed2 Mon Sep 17 00:00:00 2001 From: MrFry Date: Tue, 17 Mar 2020 18:47:26 +0100 Subject: [PATCH] Changed uesr question-answer stuff to "news" --- src/data/tabs.json | 4 --- src/pages/index.js | 55 +++++++++++++++++++++++++++++++++++--- src/pages/userQuestions.js | 51 ----------------------------------- 3 files changed, 51 insertions(+), 59 deletions(-) delete mode 100644 src/pages/userQuestions.js diff --git a/src/data/tabs.json b/src/data/tabs.json index 4634115..88d9350 100644 --- a/src/data/tabs.json +++ b/src/data/tabs.json @@ -18,9 +18,5 @@ "testSender": { "href": "/testSender", "text": "Test Sender" - }, - "userQuestions": { - "href": "/userQuestions", - "text": "User Questions" } } diff --git a/src/pages/index.js b/src/pages/index.js index 7a09144..93e8405 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -1,16 +1,29 @@ // TODO: css remove unnecesarry stuff -// TODO: resizing -// TODO: motd // TODO: aludni // TODO: fetch only once import React, { useState, useEffect } from 'react' import fetch from 'unfetch' + +import LoadingIndicator from '../components/LoadingIndicator' + import links from '../data/links.json' import constants from '../constants.json' export default function Index (props) { const [motd, setMotd] = useState('loading...') + const [news, setNews] = useState(null) + + useEffect(() => { + console.info('Fetching news.json') + fetch(`${constants.apiUrl}news.json`) // eslint-disable-line + .then((resp) => { + return resp.json() + }) + .then((data) => { + setNews(data) + }) + }, []) useEffect(() => { console.info('Fetching data') @@ -23,6 +36,39 @@ export default function Index (props) { }) }, []) + const renderNews = () => { + if (news) { + let questions = Object.keys(news).map((key, i) => { + let q = news[key] + return ( +
+
+
+ {key}: +
+
+ {q.q} +
+
+
+ {q.a} +
+
+ ) + }).reverse() + + return ( +
+ {questions} +
+ ) + } else { + return ( + + ) + } + } + const renderMotd = () => { return (
@@ -43,7 +89,7 @@ export default function Index (props) { {Object.keys(links).map((key) => { let link = links[key] return ( -
@@ -52,9 +98,10 @@ export default function Index (props) { > {link.text} -
+ ) })} + {renderNews()}
) } diff --git a/src/pages/userQuestions.js b/src/pages/userQuestions.js deleted file mode 100644 index ac4d189..0000000 --- a/src/pages/userQuestions.js +++ /dev/null @@ -1,51 +0,0 @@ -import React, { useState, useEffect } from 'react' - -import LoadingIndicator from '../components/LoadingIndicator' - -import constants from '../constants.json' - -export default function UserQuestions (props) { - const [qa, setQa] = useState(null) - - useEffect(() => { - console.info('Fetching qa.json') - fetch(`${constants.apiUrl}qa.json`) // eslint-disable-line - .then((resp) => { - return resp.json() - }) - .then((data) => { - setQa(data) - }) - }, []) - - if (qa) { - let questions = Object.keys(qa).map((key, i) => { - let q = qa[key] - return ( -
-
-
- {key}: -
-
- {q.q} -
-
-
- {q.a} -
-
- ) - }).reverse() - - return ( -
- {questions} -
- ) - } else { - return ( - - ) - } -}