forked from extern/bruno
feat: Using CodeEditor for displaying response (more performant, no flicker :D)
This commit is contained in:
parent
7c2e909488
commit
f2925022e8
@ -2,14 +2,9 @@ import styled from 'styled-components';
|
|||||||
|
|
||||||
const StyledWrapper = styled.div`
|
const StyledWrapper = styled.div`
|
||||||
div.CodeMirror {
|
div.CodeMirror {
|
||||||
border: solid 1px var(--color-codemirror-border);
|
|
||||||
/* todo: find a better way */
|
/* todo: find a better way */
|
||||||
height: calc(100vh - 255px);
|
height: calc(100vh - 255px);
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea.cm-editor {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default StyledWrapper;
|
export default StyledWrapper;
|
||||||
|
@ -1,56 +1,12 @@
|
|||||||
import React, { useState, useRef, useEffect } from 'react';
|
import React from 'react';
|
||||||
|
import CodeEditor from 'components/CodeEditor';
|
||||||
import StyledWrapper from './StyledWrapper';
|
import StyledWrapper from './StyledWrapper';
|
||||||
|
|
||||||
let CodeMirror;
|
const QueryResult = ({value, width}) => {
|
||||||
const SERVER_RENDERED = typeof navigator === 'undefined' || global['PREVENT_CODEMIRROR_RENDER'] === true;
|
|
||||||
|
|
||||||
if (!SERVER_RENDERED) {
|
|
||||||
CodeMirror = require('codemirror');
|
|
||||||
}
|
|
||||||
|
|
||||||
const QueryResult = ({data, width}) => {
|
|
||||||
const [cmEditor, setCmEditor] = useState(null);
|
|
||||||
const editor = useRef();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (editor.current && !cmEditor) {
|
|
||||||
const _cmEditor = CodeMirror.fromTextArea(editor.current, {
|
|
||||||
value: '',
|
|
||||||
lineNumbers: true,
|
|
||||||
matchBrackets: true,
|
|
||||||
autoCloseBrackets: true,
|
|
||||||
mode: "application/ld+json",
|
|
||||||
foldGutter: true,
|
|
||||||
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
|
|
||||||
readOnly: true,
|
|
||||||
lineWrapping: true
|
|
||||||
});
|
|
||||||
|
|
||||||
setCmEditor(_cmEditor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(editor.current && cmEditor && data) {
|
|
||||||
cmEditor.setValue(JSON.stringify(data, null, 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
if(cmEditor) {
|
|
||||||
cmEditor.toTextArea();
|
|
||||||
setCmEditor(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [editor.current, cmEditor, data]);
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledWrapper className="mt-4 px-3 w-full" style={{maxWidth: width}}>
|
<StyledWrapper className="mt-4 px-3 w-full" style={{maxWidth: width}}>
|
||||||
<div className="h-full">
|
<div className="h-full">
|
||||||
<textarea
|
<CodeEditor value={value || ''} />
|
||||||
id="query-result"
|
|
||||||
ref={editor}
|
|
||||||
className="cm-editor"
|
|
||||||
>
|
|
||||||
</textarea>
|
|
||||||
</div>
|
</div>
|
||||||
</StyledWrapper>
|
</StyledWrapper>
|
||||||
);
|
);
|
||||||
|
@ -26,7 +26,7 @@ const ResponsePane = ({rightPaneWidth, response, isLoading}) => {
|
|||||||
return (
|
return (
|
||||||
<QueryResult
|
<QueryResult
|
||||||
width={rightPaneWidth}
|
width={rightPaneWidth}
|
||||||
data={response.data}
|
value={response.data ? JSON.stringify(response.data, null, 2) : ''}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user