import React, { Component, Fragment } from 'react'; import { withStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; import LinearProgress from '@material-ui/core/LinearProgress'; import Typography from '@material-ui/core/Typography'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; import ListItemText from '@material-ui/core/ListItemText'; import ListItemAvatar from '@material-ui/core/ListItemAvatar'; import Avatar from '@material-ui/core/Avatar'; import Divider from '@material-ui/core/Divider'; import WifiIcon from '@material-ui/icons/Wifi'; import DNSIcon from '@material-ui/icons/Dns'; import SettingsInputComponentIcon from '@material-ui/icons/SettingsInputComponent'; import SettingsInputAntennaIcon from '@material-ui/icons/SettingsInputAntenna'; import DeviceHubIcon from '@material-ui/icons/DeviceHub'; import SectionContent from '../components/SectionContent'; import { WIFI_STATUS_ENDPOINT } from '../constants/Endpoints'; import { isConnected, connectionStatus, connectionStatusHighlight } from '../constants/WiFiConnectionStatus'; import * as Highlight from '../constants/Highlight'; import { restComponent } from '../components/RestComponent'; const styles = theme => ({ ["wifiStatus_" + Highlight.IDLE]: { backgroundColor: theme.palette.highlight_idle }, ["wifiStatus_" + Highlight.SUCCESS]: { backgroundColor: theme.palette.highlight_success }, ["wifiStatus_" + Highlight.ERROR]: { backgroundColor: theme.palette.highlight_error }, ["wifiStatus_" + Highlight.WARN]: { backgroundColor: theme.palette.highlight_warn }, fetching: { margin: theme.spacing(4), textAlign: "center" }, button: { marginRight: theme.spacing(2), marginTop: theme.spacing(2), } }); class WiFiStatus extends Component { componentDidMount() { this.props.loadData(); } dnsServers(status) { if (!status.dns_ip_1) { return "none"; } return status.dns_ip_1 + (status.dns_ip_2 ? ',' + status.dns_ip_2 : ''); } createListItems(data, classes) { return ( { isConnected(data) && IP # } ); } renderWiFiStatus(data, classes) { return (
{this.createListItems(data, classes)}
); } render() { const { data, fetched, errorMessage, classes } = this.props; return ( { !fetched ?
Loading...
: data ? this.renderWiFiStatus(data, classes) :
{errorMessage}
}
) } } export default restComponent(WIFI_STATUS_ENDPOINT, withStyles(styles)(WiFiStatus));