2016-07-16 02:06:10 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
|
|
|
import classnames from 'classnames';
|
2016-06-16 06:16:24 +00:00
|
|
|
|
2016-07-16 02:06:10 +00:00
|
|
|
import Input from './base/Input';
|
|
|
|
import Dropdown from './base/Dropdown';
|
2016-07-20 21:15:11 +00:00
|
|
|
import MethodTag from './MethodTag';
|
2016-07-20 23:16:28 +00:00
|
|
|
import {METHODS} from '../lib/constants';
|
2016-07-16 02:06:10 +00:00
|
|
|
import Mousetrap from '../lib/mousetrap';
|
2016-03-20 23:20:00 +00:00
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
|
|
|
|
class RequestUrlBar extends Component {
|
|
|
|
_handleFormSubmit (e) {
|
2016-04-26 07:29:24 +00:00
|
|
|
e.preventDefault();
|
|
|
|
this.props.sendRequest();
|
|
|
|
}
|
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
_handleUrlChange (url) {
|
2016-07-20 23:16:28 +00:00
|
|
|
this.props.onUrlChange(url);
|
2016-07-06 20:18:26 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
focus () {
|
2016-07-06 20:18:26 +00:00
|
|
|
this.refs.input.focus();
|
|
|
|
console.log('-- Focus URL Bar --');
|
|
|
|
}
|
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
componentDidMount () {
|
2016-07-06 20:18:26 +00:00
|
|
|
Mousetrap.bindGlobal('mod+l', this.focus.bind(this));
|
|
|
|
}
|
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
componentWillUnmount () {
|
2016-07-06 20:18:26 +00:00
|
|
|
Mousetrap.unbind('mod+l');
|
|
|
|
}
|
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
render () {
|
|
|
|
const {onMethodChange, url, method} = this.props;
|
2016-06-16 06:16:24 +00:00
|
|
|
|
|
|
|
// TODO: Implement proper error checking here
|
|
|
|
const hasError = !url;
|
|
|
|
|
2016-03-20 23:20:00 +00:00
|
|
|
return (
|
2016-06-16 06:16:24 +00:00
|
|
|
<div className={classnames({'urlbar': true, 'urlbar--error': hasError})}>
|
2016-05-01 19:56:30 +00:00
|
|
|
<Dropdown>
|
|
|
|
<button>
|
2016-07-20 21:15:11 +00:00
|
|
|
<div className="tall">
|
|
|
|
<span>{method}</span>
|
|
|
|
<i className="fa fa-caret-down"/>
|
|
|
|
</div>
|
2016-03-21 05:47:49 +00:00
|
|
|
</button>
|
2016-04-04 07:15:30 +00:00
|
|
|
<ul>
|
2016-04-26 07:29:24 +00:00
|
|
|
{METHODS.map(m => (
|
|
|
|
<li key={m}>
|
|
|
|
<button onClick={onMethodChange.bind(null, m)}>
|
2016-07-20 21:15:11 +00:00
|
|
|
<MethodTag method={m} fullNames={true}/>
|
2016-03-21 05:47:49 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</Dropdown>
|
2016-06-16 06:16:24 +00:00
|
|
|
<form className="form-control" onSubmit={this._handleFormSubmit.bind(this)}>
|
2016-04-29 08:15:37 +00:00
|
|
|
<Input
|
2016-07-06 20:18:26 +00:00
|
|
|
ref="input"
|
2016-04-09 21:08:55 +00:00
|
|
|
type="text"
|
|
|
|
placeholder="http://echo.insomnia.rest/status/200"
|
2016-04-26 07:29:24 +00:00
|
|
|
value={url}
|
2016-07-06 20:18:26 +00:00
|
|
|
onChange={url => this._handleUrlChange(url)}/>
|
2016-04-09 21:08:55 +00:00
|
|
|
</form>
|
2016-05-01 19:56:30 +00:00
|
|
|
<button onClick={this._handleFormSubmit.bind(this)}>
|
2016-04-18 04:39:15 +00:00
|
|
|
Send
|
2016-05-01 19:56:30 +00:00
|
|
|
</button>
|
2016-03-20 23:20:00 +00:00
|
|
|
</div>
|
2016-04-17 22:46:17 +00:00
|
|
|
);
|
2016-03-20 23:20:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
RequestUrlBar.propTypes = {
|
2016-04-09 21:08:55 +00:00
|
|
|
sendRequest: PropTypes.func.isRequired,
|
2016-03-20 23:20:00 +00:00
|
|
|
onUrlChange: PropTypes.func.isRequired,
|
2016-03-20 23:27:46 +00:00
|
|
|
onMethodChange: PropTypes.func.isRequired,
|
2016-04-26 07:29:24 +00:00
|
|
|
url: PropTypes.string.isRequired,
|
|
|
|
method: PropTypes.string.isRequired
|
2016-03-20 23:20:00 +00:00
|
|
|
};
|
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
export default RequestUrlBar;
|