From 806f32cac51aee1051d91cbb410aeef99827a27b Mon Sep 17 00:00:00 2001 From: mrfry Date: Wed, 21 Oct 2020 16:27:40 +0200 Subject: [PATCH] Added support for user specific motd --- src/pages/index.js | 105 +++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/src/pages/index.js b/src/pages/index.js index c774a65..e2d11c2 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -11,14 +11,15 @@ import styles from './index.module.css' import links from '../data/links.json' import constants from '../constants.json' -export default function Index (props) { +export default function Index(props) { const [motd, setMotd] = useState('loading...') + const [userSpecificMotd, setUserSpecificMotd] = useState('loading...') const [news, setNews] = useState(null) useEffect(() => { console.info('Fetching news.json') fetch(`${constants.apiUrl}news.json`, { - credentials: 'include' + credentials: 'include', }) .then((resp) => { return resp.json() @@ -30,23 +31,25 @@ export default function Index (props) { useEffect(() => { console.info('Fetching data') - fetch(`${constants.apiUrl}motd`, { - credentials: 'include' + fetch(`${constants.apiUrl}infos?motd=true`, { + credentials: 'include', + Accept: 'application/json', + 'Content-Type': 'application/json', }) .then((resp) => { - return resp.text() + return resp.json() }) .then((data) => { - setMotd(data) + console.log(data) + setMotd(data.motd) + setUserSpecificMotd(data.userSpecificMotd) }) }, []) const renderQAItem = (n, key) => { return (
-
- {key} : -
+
{key} :
{ return (
-
- {key} : -
+
{key} :
{ if (news) { - let questions = Object.keys(news).map((key, i) => { - let n = news[key] - if (n.q) { - return ( -
- {renderQAItem(n, key)} -
-
- ) - } else { - return ( -
- {renderNewsItem(n, key)} -
-
- ) - } - }).reverse() + let questions = Object.keys(news) + .map((key, i) => { + let n = news[key] + if (n.q) { + return ( +
+ {renderQAItem(n, key)} +
+
+ ) + } else { + return ( +
+ {renderNewsItem(n, key)} +
+
+ ) + } + }) + .reverse() - return ( -
- {questions} -
- ) + return
{questions}
} else { - return ( - - ) + return } } const renderMotd = () => { return (
-
- MOTD: -
+
MOTD:
{ + return ( +
+
+ Felhasználó MOTD (ezt csak te látod): +
+
+
+ ) + } + return (
{renderMotd()} + {userSpecificMotd && renderUserSpecificMotd()}
{Object.keys(links).map((key) => { let link = links[key] return ( - - -
- {link.text} -
+ +
+
{link.text}
)