import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import Axios from 'axios'; import Widget from './Widget'; import { Container, Row, Spinner } from 'react-bootstrap'; import { Col } from 'react-bootstrap'; import { Button } from 'react-bootstrap'; import { toast } from 'react-toastify'; export default class LatestResults extends Component { constructor(props) { super(props) this.state = { data: props.data, interval: null, loading: true, } } componentDidUpdate() { if(this.state.data !== this.props.data) { this.setState({ data: this.props.data, loading: false, }); } } componentWillUnmount() { clearInterval(this.state.interval); } newScan = () => { var url = 'api/speedtest/run?token=' + window.token; Axios.get(url) .then((resp) => { toast.info('A test has been queued. This page will refresh when the test has finished.'); }) .catch((err) => { if(err.response) { if(err.response.status == 429) { toast.error('You are doing that too much. Try again later.'); } console.log(err.response); } else { console.log(err.data); } }) } render() { var loading = this.state.loading; var data = this.state.data; if(loading && data !== false) { return ( ); } else if(data === false) { if( (window.config.auth == true && window.authenticated == true) || window.config.auth == false) { return (
); } else if(window.config.auth == true && window.authenticated == false) { return (

Please login to run the first test

); } } else { return (
{(window.config.auth == true && window.authenticated == true) || window.config.auth == false ?

Last test performed at: {new Date(data.data.created_at).toLocaleString()}

:

Last test performed at: {new Date(data.data.created_at).toLocaleString()}

}
); } } } if (document.getElementById('LatestResults')) { ReactDOM.render(, document.getElementById('LatestResults')); }