2016-07-16 02:06:10 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-08-15 17:04:36 +00:00
|
|
|
import Editor from '../base/Editor';
|
|
|
|
import ResponseWebview from './ResponseWebview';
|
2016-09-10 02:51:24 +00:00
|
|
|
import ResponseRaw from './ResponseRaw';
|
2016-08-25 17:06:01 +00:00
|
|
|
import ResponseError from './ResponseError';
|
2016-08-31 05:37:21 +00:00
|
|
|
import {
|
|
|
|
PREVIEW_MODE_FRIENDLY,
|
|
|
|
PREVIEW_MODE_SOURCE
|
2016-09-21 00:03:26 +00:00
|
|
|
} from 'backend/previewModes';
|
2016-04-30 05:01:57 +00:00
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
class ResponseViewer extends Component {
|
2016-08-04 04:12:45 +00:00
|
|
|
shouldComponentUpdate (nextProps) {
|
|
|
|
for (let k of Object.keys(nextProps)) {
|
2016-09-18 22:58:50 +00:00
|
|
|
const prop = nextProps[k];
|
|
|
|
if (typeof prop !== 'function' && this.props[k] !== prop) {
|
2016-08-04 04:12:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-30 05:01:57 +00:00
|
|
|
render () {
|
2016-07-19 22:28:29 +00:00
|
|
|
const {
|
|
|
|
previewMode,
|
2016-09-09 00:32:36 +00:00
|
|
|
filter,
|
2016-07-19 22:28:29 +00:00
|
|
|
contentType,
|
|
|
|
editorLineWrapping,
|
|
|
|
editorFontSize,
|
2016-09-09 00:32:36 +00:00
|
|
|
updateFilter,
|
2016-07-19 22:28:29 +00:00
|
|
|
body,
|
2016-08-25 17:06:01 +00:00
|
|
|
url,
|
|
|
|
error
|
2016-07-19 22:28:29 +00:00
|
|
|
} = this.props;
|
2016-04-30 05:01:57 +00:00
|
|
|
|
2016-08-25 17:06:01 +00:00
|
|
|
if (error) {
|
|
|
|
return (
|
2016-09-09 00:32:36 +00:00
|
|
|
<ResponseError url={url} error={body}/>
|
2016-08-25 17:06:01 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-04-30 05:01:57 +00:00
|
|
|
switch (previewMode) {
|
|
|
|
case PREVIEW_MODE_FRIENDLY:
|
|
|
|
return (
|
2016-08-15 17:04:36 +00:00
|
|
|
<ResponseWebview
|
2016-05-01 19:56:30 +00:00
|
|
|
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 || ''}
|
2016-09-09 00:32:36 +00:00
|
|
|
updateFilter={updateFilter}
|
|
|
|
filter={filter}
|
2016-09-13 17:29:09 +00:00
|
|
|
autoPrettify={true}
|
2016-05-01 19:56:30 +00:00
|
|
|
mode={contentType}
|
|
|
|
readOnly={true}
|
2016-07-19 22:28:29 +00:00
|
|
|
lineWrapping={editorLineWrapping}
|
|
|
|
fontSize={editorFontSize}
|
2016-08-31 05:37:21 +00:00
|
|
|
placeholder="..."
|
2016-05-01 19:56:30 +00:00
|
|
|
/>
|
2016-04-30 05:01:57 +00:00
|
|
|
);
|
|
|
|
default: // Raw
|
|
|
|
return (
|
2016-09-21 01:25:46 +00:00
|
|
|
<ResponseRaw value={body} fontSize={editorFontSize}/>
|
2016-04-30 05:01:57 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
ResponseViewer.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-09-09 00:32:36 +00:00
|
|
|
filter: PropTypes.string.isRequired,
|
2016-07-19 22:28:29 +00:00
|
|
|
editorFontSize: PropTypes.number.isRequired,
|
|
|
|
editorLineWrapping: PropTypes.bool.isRequired,
|
2016-07-28 20:10:26 +00:00
|
|
|
url: PropTypes.string.isRequired,
|
|
|
|
|
|
|
|
// Optional
|
2016-09-09 00:32:36 +00:00
|
|
|
updateFilter: PropTypes.func,
|
2016-08-25 17:06:01 +00:00
|
|
|
contentType: PropTypes.string,
|
|
|
|
error: PropTypes.bool
|
2016-04-30 05:01:57 +00:00
|
|
|
};
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
export default ResponseViewer;
|