insomnia/app/components/ResponseViewer.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-04-30 05:01:57 +00:00
import React, {Component, PropTypes} from 'react'
import Editor from '../components/base/Editor'
import ResponseBodyWebview from '../components/ResponseBodyWebview'
import {PREVIEW_MODE_FRIENDLY, PREVIEW_MODE_SOURCE} from '../lib/previewModes'
class ResponseViewer extends Component {
render () {
2016-06-18 21:02:27 +00:00
const {previewMode, contentType, body, 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-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
wrap: PropTypes.bool
2016-04-30 05:01:57 +00:00
};
export default ResponseViewer;