include server config fetch in serverstatus context hook so config data can be provided across multiple views

This commit is contained in:
gingervitis
2020-11-13 04:43:27 -08:00
parent 72d9ff4edb
commit e3c0265469
7 changed files with 81 additions and 140 deletions

View File

@@ -1,7 +1,7 @@
/* eslint-disable react/prop-types */
import React, { useState, useEffect } from "react";
import { SERVER_CONFIG, fetchData, FETCH_INTERVAL } from "../utils/apis";
import React, { useContext } from "react";
import KeyValueTable from "./components/key-value-table";
import { ServerStatusContext } from '../utils/server-status-context';
function Storage({ config }) {
if (!config || !config.s3) {
@@ -47,30 +47,8 @@ function Storage({ config }) {
}
export default function ServerConfig() {
const [config, setConfig] = useState({});
const getInfo = async () => {
try {
const result = await fetchData(SERVER_CONFIG);
console.log("viewers result", result);
setConfig({ ...result });
} catch (error) {
setConfig({ ...config, message: error.message });
}
};
useEffect(() => {
let getStatusIntervalId = null;
getInfo();
getStatusIntervalId = setInterval(getInfo, FETCH_INTERVAL);
// returned function will be called on component unmount
return () => {
clearInterval(getStatusIntervalId);
};
}, []);
const serverStatusData = useContext(ServerStatusContext);
const { serverConfig: config } = serverStatusData || {};
return (
<div>