import React from 'react'; import { ScrollView, StyleSheet, Modal, Text, TextInput, TouchableOpacity, View, Platform, } from 'react-native'; import {Button} from 'react-native-elements' import PivotCircle from "../components/PivotCircle"; import { NavigationActions } from 'react-navigation' var KeyWordHelpers = require("../components/KeyWordHelpers") var _ = require('lodash'); // Mobx state stores import { inject, observer, Provider } from 'mobx-react'; import { observable, action } from "mobx"; import stores from '../stores/stores'; @observer export default class SiteControlScreen extends React.Component { constructor(props) { super(props); this.state = { activeCommand: "null", activeCommandText: "null", commandedSpeed: "null", confirmModalVisible: false } } componentWillMount(){ console.log(`props be ${this.props.navigation.navigate }`) } backToSummary(){ const resetAction = NavigationActions.reset({ index: 0, actions: [NavigationActions.navigate({routeName: 'Main'})] }) this.props.navigation.dispatch(resetAction); } getConfirm(){ this.state.confirmModalVisible = true; } cancelCommand(){ console.log("cancel even fired"); this.setState({confirmModalVisible: false}) } sendSimpleCommand = async () => { this.setState({confirmModalVisible: false}) site = stores.systemStore.activeSite; console.log(`found state command to be ${this.state.activeCommand}`); if (this.state.activeCommand == "null"){ console.log("delay on state update.. better try this again"); setTimeout(this.sendSimpleCommand, 1000); }else{ var apiURL = "http://api.pivotrac.com/out_command/send_simple_command" var apiParams = '?device=android&site=' + site.id + "&command=" + this.state.activeCommand; var requestURL = apiURL + apiParams; console.log(requestURL); await fetch(requestURL) .then((response) => response.json()) .then((responseData) => { alert(this.state.activeCommandText); }) } } sendSpeed(){ speedCommand = `set_speed_${this.state.commandedSpeed}` this.setState({activeCommand: speedCommand}) this.setState({activeCommandText: `setting ${stores.systemStore.activeSite.name} to ${this.state.commandedSpeed} ` }) this.getConfirm(); } sendDryMode(){ this.setState({activeCommand: "set_dry_mode"}) this.setState({activeCommandText: `setting ${stores.systemStore.activeSite.name} to dry mode` }) this.getConfirm(); } sendWetMode(){ this.setState({activeCommand: "set_wet_mode"}) this.setState({activeCommandText: `setting ${stores.systemStore.activeSite.name} to wet mode` }) this.getConfirm(); } sendAuto(){ this.setState({activeCommand: "auto"}) this.setState({activeCommandText: `setting ${stores.systemStore.activeSite.name} to auto mode` }) this.getConfirm(); } sendManual(){ this.setState({activeCommand: "manual"}) this.setState({activeCommandText: `setting ${stores.systemStore.activeSite.name} to manual mode` }) this.getConfirm(); } enableSchedule(){ this.setState({activeCommand: "enable_schedule"}) this.setState({activeCommandText: `enable scheduled commands for ${stores.systemStore.activeSite.name}` }) this.getConfirm(); } disableSchedule(){ this.setState({activeCommand: "disable_schedule"}) this.setState({activeCommandText: `disable scheduled commands for ${stores.systemStore.activeSite.name}` }) this.getConfirm(); } sendReverse(){ this.setState({activeCommand: "reverse"}) this.setState({activeCommandText: `sending reverse command to ${stores.systemStore.activeSite.name} ` }) this.getConfirm(); } sendForward(){ this.setState({activeCommand: "forward"}) this.setState({activeCommandText: `sending forward command to ${stores.systemStore.activeSite.name}` }) this.getConfirm(); } sendStop(){ this.setState({activeCommand: "stop"}) this.setState({activeCommandText: `sending stop command to ${stores.systemStore.activeSite.name} ` }) this.getConfirm(); } sendStart(){ this.setState({activeCommand: "start"}) this.setState({activeCommandText: `sending start command to ${stores.systemStore.activeSite.name} ` }) this.getConfirm(); } render() { site = stores.systemStore.activeSite; if (Platform.OS == "ios"){ kbd = "numbers-and-punctuation" }else{ kbd = "numeric" } return( {this.state.activeCommandText}