insomnia/app/ui/components/viewers/response-webview.js
Gregory Schier 8452e8b777 Some eslint refactoring (#109)
* Fixed duplication kve bug

* Some changes

* Add proptypes linting

* Fixed proptypes even more

* Filename linting
2017-03-07 21:52:17 -08:00

45 lines
1.1 KiB
JavaScript

import React, {PureComponent, PropTypes} from 'react';
import autobind from 'autobind-decorator';
import contextMenu from 'electron-context-menu';
@autobind
class ResponseWebview extends PureComponent {
_handleSetWebviewRef (n) {
this._webview = n;
contextMenu({window: this._webview});
}
_handleDOMReady () {
this._webview.removeEventListener('dom-ready', this._handleDOMReady);
this._setBody();
}
_setBody () {
const {body, contentType, url} = this.props;
const newBody = body.replace('<head>', `<head><base href="${url}">`);
this._webview.loadURL(`data:${contentType},${encodeURIComponent(newBody)}`);
}
componentDidUpdate () {
this._setBody();
}
componentDidMount () {
this._webview.addEventListener('dom-ready', this._handleDOMReady);
}
render () {
return (
<webview ref={this._handleSetWebviewRef} src="about:blank"></webview>
);
}
}
ResponseWebview.propTypes = {
body: PropTypes.string.isRequired,
contentType: PropTypes.string.isRequired,
url: PropTypes.string.isRequired
};
export default ResponseWebview;