insomnia/app/ui/components/viewers/ResponseWebview.js
Gregory Schier bb57f360e0 Environment Tags and Such (#90)
* Sort of working nunjucks editor

* Some more tweaks

* Lots of stuff

* Gettingn pretty good

* Minor tweaks and test fixes

* Minor bug fixes and stuff

* Some fixes and perf

* Refactoring

* Good for now

* Codemirror URL

* More and more fixes and improvements

* Code single-line CSS perfect!!!

* Better nj editing

* Show preview in nj edit

* Some editor updates

* All inputs now covered

* A bunch of fixes and stuff

* Don't cache node modules because it's not needed

* More stuff

* Tweak

* Style tweaks

* Pull nunjucks mode into own file

* Move codemirror click overlay to own file

* Pull nunjucks tag stuff out

* Fixed key value editor

* raw/endraw and marks improvements

* Some tweaks
2017-02-27 13:00:13 -08:00

43 lines
1.0 KiB
JavaScript

import React, {PureComponent, PropTypes} from 'react';
import contextMenu from 'electron-context-menu';
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;