|
| 1 | +import React from 'react'; |
| 2 | +import { addons } from 'react/addons'; |
| 3 | +import ConnectionActions from '../actions/connection-actions'; |
| 4 | + |
| 5 | +const component = React.createClass({ |
| 6 | + mixins: [addons.PureRenderMixin], |
| 7 | + |
| 8 | + getInitialState() { |
| 9 | + return {isConnecting: false}; |
| 10 | + }, |
| 11 | + |
| 12 | + handleChange(key, event) { |
| 13 | + this.setState({ |
| 14 | + [key]: event.target.value |
| 15 | + }); |
| 16 | + }, |
| 17 | + |
| 18 | + handleFormSubmission(event) { |
| 19 | + event.preventDefault(); |
| 20 | + this.setState({isConnecting: true}); |
| 21 | + |
| 22 | + const { realName, nickname, password, server, port } = this.state; |
| 23 | + ConnectionActions.requestConnection({ |
| 24 | + realName, nickname, password, server, port: parseInt(port, 10) |
| 25 | + }); |
| 26 | + }, |
| 27 | + |
| 28 | + render() { |
| 29 | + const inputGroupClass = 'input-group'; |
| 30 | + const serverOptions = ['chat.freenode.net']; |
| 31 | + |
| 32 | + return ( |
| 33 | + <form className="connection-creator" onSubmit={this.handleFormSubmission}> |
| 34 | + <div className={inputGroupClass}> |
| 35 | + <label>Real Name</label> |
| 36 | + <input type="text" |
| 37 | + autoFocus |
| 38 | + required |
| 39 | + onChange={this.handleChange.bind(this, 'realName')} /> |
| 40 | + </div> |
| 41 | + |
| 42 | + <div className={inputGroupClass}> |
| 43 | + <label>Nickname</label> |
| 44 | + <input type="text" |
| 45 | + required |
| 46 | + onChange={this.handleChange.bind(this, 'nickname')} /> |
| 47 | + </div> |
| 48 | + |
| 49 | + <div className={inputGroupClass}> |
| 50 | + <label>Password</label> |
| 51 | + <input type="password" |
| 52 | + onChange={this.handleChange.bind(this, 'password')} /> |
| 53 | + </div> |
| 54 | + |
| 55 | + <div className={inputGroupClass}> |
| 56 | + <label>Server</label> |
| 57 | + <select required |
| 58 | + onChange={this.handleChange.bind(this, 'server')}> |
| 59 | + <option value=""></option> |
| 60 | + {serverOptions.map((n, i) => { |
| 61 | + return <option value={n} key={i}>{n}</option> |
| 62 | + })} |
| 63 | + </select> |
| 64 | + </div> |
| 65 | + |
| 66 | + <div className={inputGroupClass}> |
| 67 | + <label>Port</label> |
| 68 | + <input type="number" |
| 69 | + required |
| 70 | + onChange={this.handleChange.bind(this, 'port')} /> |
| 71 | + </div> |
| 72 | + |
| 73 | + <input type="submit" disabled={this.state.isConnecting} /> |
| 74 | + </form> |
| 75 | + ); |
| 76 | + } |
| 77 | +}); |
| 78 | + |
| 79 | +module.exports = component; |
0 commit comments