import React, { useState, useEffect } from 'react'
import Header from '../components/header'
import constants from '../constants'
import LoadingIndicator from '../components/LoadingIndicator'
import styles from './p2pinfo.module.css'
const infos = [
{
title: 'Név',
key: 'name',
},
{
title: 'Kontakt',
key: 'contact',
},
{
title: 'Utolsó szinkronizálás',
key: 'lastSync',
type: 'date',
},
{
title: 'Felhasználók',
key: 'userCount',
type: 'number',
},
{
title: 'Kérdés DB-k',
key: 'questionDbCount',
type: 'number',
},
{
title: 'Tárgyak',
key: 'subjectCount',
type: 'number',
},
{
title: 'Kérdések',
key: 'questionCount',
type: 'number',
},
{
title: 'Script version',
key: 'scriptVersion',
},
{
title: 'Szerver build time',
key: 'serverBuildTime',
type: 'date',
},
{
title: 'Weboldal build time',
key: 'qminingPageBuildTime',
type: 'date',
},
{
title: 'Data editor build time',
key: 'dataEditorBuildTime',
type: 'date',
},
{
title: 'Szerver utolsó commit date',
key: 'serverLastCommitDate',
type: 'date',
},
{
title: 'Script utolsó commit date',
key: 'scriptLastCommitDate',
type: 'date',
},
{
title: 'Weboldal utolsó commit date',
key: 'qminingPageLastCommitDate',
type: 'date',
},
{
title: 'Data editor utolsó commit date',
key: 'dataEditorLastCommitDate',
type: 'date',
},
{
title: 'Szerver revision',
key: 'serverRevision',
},
{
title: 'Script revision',
key: 'scriptRevision',
},
{
title: 'Weboldal revision',
key: 'qminingPageRevision',
},
{
title: 'Data editor revision',
key: 'dataEditorRevision',
},
]
function getDateString(dateNumber) {
if (Number.isNaN(+dateNumber)) {
return ' - '
}
return new Date(dateNumber).toLocaleString()
}
export default function P2PInfo({ globalState, setGlobalState }) {
const [p2pInfo, setP2pinfo] = useState()
const info = p2pInfo
? {
...p2pInfo,
...p2pInfo.selfInfo,
...p2pInfo.qdbInfo,
}
: {}
useEffect(() => {
if (globalState.p2pinfo) {
setP2pinfo(globalState.p2pinfo)
} else {
fetch(constants.apiUrl + 'p2pinfo', {
method: 'GET',
credentials: 'include',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then((res) => {
return res.json()
})
.then((res) => {
setP2pinfo(res)
setGlobalState({
p2pinfo: res,
})
})
}
}, [])
if (!p2pInfo) return