2016-07-16 02:06:10 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-04-30 05:01:57 +00:00
|
|
|
|
2016-07-16 02:06:10 +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 ResponseViewer extends Component {
|
|
|
|
render () {
|
2016-06-19 07:21:43 +00:00
|
|
|
const {previewMode, contentType, body, url, wrap} = 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-06-18 21:02:27 +00:00
|
|
|
lineWrapping={wrap}
|
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
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResponseViewer.propTypes = {
|
|
|
|
body: PropTypes.string.isRequired,
|
|
|
|
contentType: PropTypes.string.isRequired,
|
2016-06-18 21:02:27 +00:00
|
|
|
previewMode: PropTypes.string.isRequired,
|
|
|
|
|
|
|
|
// Optional
|
2016-06-20 06:05:40 +00:00
|
|
|
wrap: PropTypes.bool,
|
|
|
|
url: PropTypes.string
|
2016-04-30 05:01:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponseViewer;
|