import React, { useState, useEffect } from 'react' import fetch from 'unfetch' import Head from 'next/head' import Link from 'next/link' import LoadingIndicator from '../components/LoadingIndicator' import Sleep from '../components/sleep' import styles from './index.module.css' import links from '../data/links.json' import constants from '../constants.json' export default function Index() { 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', }) .then((resp) => { return resp.json() }) .then((data) => { setNews(data) }) }, []) useEffect(() => { console.info('Fetching data') fetch(`${constants.apiUrl}infos?motd=true`, { credentials: 'include', Accept: 'application/json', 'Content-Type': 'application/json', }) .then((resp) => { return resp.json() }) .then((data) => { setMotd(data.motd) setUserSpecificMotd(data.userSpecificMotd) }) }, []) const renderQAItem = (n, key) => { return (
{key} :
) } const renderNewsItem = (n, key) => { return (
{key} :
) } const renderNews = () => { 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() return (
News


{questions}
) } else { return } } const renderMotd = () => { return (
MOTD


) } const renderUserSpecificMotd = () => { return (
Felhasználó MOTD (ezt csak te látod):
) } return (
Qmining | Frylabs.net
{Object.keys(links).map((key) => { let link = links[key] return ( {link.text} ) })}

{renderMotd()} {userSpecificMotd && renderUserSpecificMotd()}

{renderNews()}
) }