Changed uesr question-answer stuff to "news"

This commit is contained in:
MrFry 2020-03-17 18:47:26 +01:00
parent d6be410bf0
commit c1f019956a
3 changed files with 51 additions and 59 deletions

View file

@ -18,9 +18,5 @@
"testSender": { "testSender": {
"href": "/testSender", "href": "/testSender",
"text": "Test Sender" "text": "Test Sender"
},
"userQuestions": {
"href": "/userQuestions",
"text": "User Questions"
} }
} }

View file

@ -1,16 +1,29 @@
// TODO: css remove unnecesarry stuff // TODO: css remove unnecesarry stuff
// TODO: resizing
// TODO: motd
// TODO: aludni // TODO: aludni
// TODO: fetch only once // TODO: fetch only once
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import fetch from 'unfetch' import fetch from 'unfetch'
import LoadingIndicator from '../components/LoadingIndicator'
import links from '../data/links.json' import links from '../data/links.json'
import constants from '../constants.json' import constants from '../constants.json'
export default function Index (props) { export default function Index (props) {
const [motd, setMotd] = useState('loading...') 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(() => { useEffect(() => {
console.info('Fetching data') 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 (
<div key={key} className='uquestioncontainer'>
<div >
<div className='uquestionnumber'>
{key}:
</div>
<div className='uquestion'>
{q.q}
</div>
</div>
<div className='uanswer'>
{q.a}
</div>
</div>
)
}).reverse()
return (
<div className='uquestionscontainer'>
{questions}
</div>
)
} else {
return (
<LoadingIndicator />
)
}
}
const renderMotd = () => { const renderMotd = () => {
return ( return (
<div> <div>
@ -43,7 +89,7 @@ export default function Index (props) {
{Object.keys(links).map((key) => { {Object.keys(links).map((key) => {
let link = links[key] let link = links[key]
return ( return (
<div <span
className='link' className='link'
key={key} key={key}
> >
@ -52,9 +98,10 @@ export default function Index (props) {
> >
{link.text} {link.text}
</a> </a>
</div> </span>
) )
})} })}
{renderNews()}
</div> </div>
) )
} }

View file

@ -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 (
<div key={key} className='uquestioncontainer'>
<div >
<div className='uquestionnumber'>
{key}:
</div>
<div className='uquestion'>
{q.q}
</div>
</div>
<div className='uanswer'>
{q.a}
</div>
</div>
)
}).reverse()
return (
<div className='uquestionscontainer'>
{questions}
</div>
)
} else {
return (
<LoadingIndicator />
)
}
}