import React, {Component, PropTypes} from 'react';
import Editor from '../base/Editor';
import ResponseWebView from './ResponseWebview';
import ResponseRaw from './ResponseRaw';
import ResponseError from './ResponseError';
import {LARGE_RESPONSE_MB, PREVIEW_MODE_FRIENDLY, PREVIEW_MODE_SOURCE} from '../../../common/constants';
let alwaysShowLargeResponses = false;
class ResponseViewer extends Component {
state = {
blockingBecauseTooLarge: false
};
_handleDismissBlocker () {
this.setState({blockingBecauseTooLarge: false});
}
_handleDisableBlocker () {
alwaysShowLargeResponses = true;
this._handleDismissBlocker();
}
_checkResponseBlocker (props) {
if (alwaysShowLargeResponses) {
return;
}
// Block the response if it's too large
if (props.bytes > LARGE_RESPONSE_MB * 1024 * 1024) {
this.setState({blockingBecauseTooLarge: true});
}
}
componentWillMount () {
this._checkResponseBlocker(this.props);
}
componentWillReceiveProps (nextProps) {
this._checkResponseBlocker(nextProps);
}
shouldComponentUpdate (nextProps, nextState) {
for (let k of Object.keys(nextProps)) {
const value = nextProps[k];
if (typeof value !== 'function' && this.props[k] !== value) {
return true;
}
}
for (let k of Object.keys(nextState)) {
const value = nextState[k];
if (typeof value !== 'function' && this.state[k] !== value) {
return true;
}
}
return false;
}
render () {
const {
previewMode,
filter,
contentType,
editorLineWrapping,
editorFontSize,
editorKeyMap,
updateFilter,
statusCode,
body: base64Body,
encoding,
url,
error
} = this.props;
const bodyBuffer = new Buffer(base64Body, encoding);
if (error) {
return (
Previewing responses over {LARGE_RESPONSE_MB}MB may cause slowdowns on some computers
{" "}