import * as classNames from "classnames"; import { observer } from "mobx-react"; import * as React from "react"; import { Grid, Header, Icon, Item, SemanticICONS } from "semantic-ui-react"; import * as p from "@app/pages"; import * as rp from "@app/routePaths"; import { AppState, injectState } from "@app/state"; import { ConnectionState as ConState } from "@common/sprinklersRpc"; import { Route, RouteComponentProps, withRouter } from "react-router"; import { ProgramTable, RunSectionForm, SectionRunnerView, SectionTable } from "."; import "./DeviceView.scss"; const ConnectionState = observer(({ connectionState, className }: { connectionState: ConState, className?: string }) => { const connected = connectionState.isDeviceConnected; let connectionText: string; let iconName: SemanticICONS = "unlinkify"; let clazzName: string = "disconnected"; if (connected) { connectionText = "Connected"; iconName = "linkify"; clazzName = "connected"; } else if (connected === false) { connectionText = "Device Disconnected"; } else if (connectionState.noPermission) { connectionText = "No permission for this device"; iconName = "ban"; } else if (connectionState.clientToServer === false) { connectionText = "Disconnected from server"; } else { connectionText = "Unknown"; iconName = "question"; clazzName = "unknown"; } const classes = classNames("connectionState", clazzName, className); return (
  {connectionText}
); }); interface DeviceViewProps { deviceId: string; appState: AppState; } class DeviceView extends React.Component> { render() { const { uiStore, sprinklersRpc, routerStore } = this.props.appState; const device = sprinklersRpc.getDevice(this.props.deviceId); const { id, connectionState, sections, sectionRunner } = device; const deviceBody = connectionState.isAvailable && ( ); return (
Device {id}
Raspberry Pi Grinklers Device {deviceBody}
); } } export default injectState(withRouter(observer(DeviceView)));