import React from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import ReactGA from 'react-ga'; import Modal from './Modal'; import Link from '../../components/Link'; import Icon from '../../components/Icon'; import ColourField from '../../components/Fields/ColourField'; import IconField from '../../components/Fields/IconField'; import TextField from '../../components/Fields/TextField'; import * as pusherActions from '../../services/pusher/actions'; import * as uiActions from '../../services/ui/actions'; import * as helpers from '../../helpers'; class EditCommand extends React.Component { constructor(props) { super(props); this.state = { id: helpers.generateGuid(), icon: 'power_settings_new', name: '', colour: '', url: `https://${window.location.hostname}/broadlink/sendCommand/power/`, method: 'GET', post_data: '', additional_headers: '', }; } componentDidMount() { if (this.props.command) { this.props.uiActions.setWindowTitle('Edit command'); this.setState(this.props.command); } else { this.props.uiActions.setWindowTitle('Create command'); } } handleSubmit(e) { e.preventDefault(); this.props.pusherActions.setCommand(this.state); window.history.back(); // A bit hacky, but wait for a moment to allow the back navigation // and then scroll down to our commands list setTimeout(() => { helpers.scrollTo('#commands-setup'); }, 10); return false; } handleDelete(e) { this.props.pusherActions.removeCommand(this.state.id); window.history.back(); // A bit hacky, but wait for a moment to allow the back navigation // and then scroll down to our commands list setTimeout(() => { helpers.scrollTo('#commands-setup'); }, 10); } render() { const icons = [ 'power_settings_new', 'eject', 'grade', 'query_builder', 'settings_input_component', 'settings_input_hdmi', 'settings_input_svideo', 'forward_5', 'forward_10', 'forward_30', 'replay', 'replay_5', 'replay_10', 'replay_30', 'skip_next', 'skip_previous', 'play_arrow', 'pause', 'stop', 'shuffle', 'snooze', 'volume_off', 'volume_down', 'volume_up', 'arrow_left', 'arrow_drop_up', 'arrow_right', 'arrow_drop_down', 'done', 'done_all', 'add', 'remove', 'clear', 'cast', 'speaker', 'speaker_group', 'audiotrack', 'videogame_asset', 'computer', 'tv', ]; return (

{this.props.command ? 'Edit' : 'Create'} {' '} command

this.handleSubmit(e)}>
Name
this.setState({ name: value })} />
Colour
this.setState({ colour })} />
Icon
this.setState({ icon })} />
URL
this.setState({ url: value })} />
Method
{this.state.method == 'POST' && (
Data