insomnia/app/components/ResponseBodyViewer.js

61 lines
1.5 KiB
JavaScript
Raw Normal View History

import React, {Component, PropTypes} from 'react';
2016-04-30 05:01:57 +00:00
import Editor from '../components/base/Editor';
import ResponseBodyWebview from '../components/ResponseBodyWebview';
import {PREVIEW_MODE_FRIENDLY, PREVIEW_MODE_SOURCE} from '../lib/previewModes';
2016-04-30 05:01:57 +00:00
class ResponseBodyViewer extends Component {
2016-04-30 05:01:57 +00:00
render () {
2016-07-19 22:28:29 +00:00
const {
previewMode,
contentType,
editorLineWrapping,
editorFontSize,
body,
url
} = this.props;
2016-04-30 05:01:57 +00:00
switch (previewMode) {
case PREVIEW_MODE_FRIENDLY:
return (
2016-05-01 19:56:30 +00:00
<ResponseBodyWebview
body={body}
contentType={contentType}
2016-06-19 07:21:43 +00:00
url={url}
2016-05-01 19:56:30 +00:00
/>
2016-04-30 05:01:57 +00:00
);
case PREVIEW_MODE_SOURCE:
return (
2016-05-01 19:56:30 +00:00
<Editor
value={body || ''}
prettify={true}
mode={contentType}
readOnly={true}
2016-07-19 22:28:29 +00:00
lineWrapping={editorLineWrapping}
fontSize={editorFontSize}
2016-05-01 19:56:30 +00:00
placeholder="nothing yet..."
/>
2016-04-30 05:01:57 +00:00
);
default: // Raw
return (
2016-05-01 19:56:30 +00:00
<pre className="scrollable wide tall selectable monospace pad">
{body}
</pre>
2016-04-30 05:01:57 +00:00
)
}
}
}
ResponseBodyViewer.propTypes = {
2016-04-30 05:01:57 +00:00
body: PropTypes.string.isRequired,
2016-06-18 21:02:27 +00:00
previewMode: PropTypes.string.isRequired,
2016-07-19 22:28:29 +00:00
editorFontSize: PropTypes.number.isRequired,
editorLineWrapping: PropTypes.bool.isRequired,
url: PropTypes.string.isRequired,
// Optional
contentType: PropTypes.string
2016-04-30 05:01:57 +00:00
};
export default ResponseBodyViewer;