import React, {Component} from 'react'; import {Box, List, ListItem, ListItemText} from '@material-ui/core'; import { FormButton, restController, RestControllerProps, RestFormLoader, SectionContent } from '../components'; import {ENDPOINT_ROOT} from "../api"; import {GeneralInformaitonState} from "./types"; import RefreshIcon from "@material-ui/icons/Refresh"; // define api endpoint export const GENERALINFORMATION_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "generalinfo"; type GeneralInformationRestControllerProps = RestControllerProps; class GeneralInformation extends Component { intervalhandler: number | undefined; componentDidMount() { this.props.loadData(); // this.intervalhandler = window.setInterval(() => { // this.props.loadData(); // console.log("refreshing data"); // console.log(this.props.data) // }, 10000); } componentWillUnmount() { clearInterval(this.intervalhandler); } render() { return ( ( <> } variant="contained" color="secondary" onClick={this.props.loadData}> Refresh Version: {props.data.version} )} /> ); } /** * stringify seconds to a pretty format * @param sec number of seconds */ stringifyTime(sec: number): string { if (sec >= 86400) { // display days return (Math.trunc(sec / 86400) + "d " + Math.trunc((sec % 86400) / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec"); } else if (sec >= 3600) { // display hours return (Math.trunc(sec / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec"); } else if (sec >= 60) { // only seconds and minutes return (Math.trunc(sec / 60) + "min " + sec % 60 + "sec"); } else { // only seconds return (sec + "sec"); } } } export default restController(GENERALINFORMATION_SETTINGS_ENDPOINT, GeneralInformation);