feat: dragbar adjusting request and response panes

This commit is contained in:
Anoop M D 2022-01-26 15:34:46 +05:30
parent 48f1d7119f
commit 1b78a2c223
5 changed files with 40 additions and 31 deletions

View File

@ -1,6 +1,18 @@
import styled from 'styled-components'; import styled from 'styled-components';
const StyledWrapper = styled.div` const StyledWrapper = styled.div`
div.drag-request {
display: flex;
width: 0.5rem;
padding: 0;
cursor: col-resize;
background: transparent;
border-left: solid 1px var(--color-request-dragbar-background);
&:hover {
border-left: solid 1px var(--color-request-dragbar-background-active);
}
}
`; `;
export default StyledWrapper; export default StyledWrapper;

View File

@ -18,37 +18,41 @@ const RequestTabPanel = ({dispatch, actions, collections, activeRequestTabId, re
return <div></div>; return <div></div>;
} }
let asideWidth = 200; let asideWidth = 230;
let { let {
schema schema
} = useGraphqlSchema('https://api.spacex.land/graphql'); } = useGraphqlSchema('https://api.spacex.land/graphql');
const [leftPaneWidth, setLeftPaneWidth] = useState(500); const [leftPaneWidth, setLeftPaneWidth] = useState((window.innerWidth - asideWidth)/2 - 10); // 10 is for dragbar
const [rightPaneWidth, setRightPaneWidth] = useState(window.innerWidth - 700 - asideWidth); const [rightPaneWidth, setRightPaneWidth] = useState((window.innerWidth - asideWidth)/2);
console.log((window.innerWidth - asideWidth)/2);
const [dragging, setDragging] = useState(false); const [dragging, setDragging] = useState(false);
const handleMouseMove = (e) => { const handleMouseMove = (e) => {
e.preventDefault();
if(dragging) { if(dragging) {
e.preventDefault();
setLeftPaneWidth(e.clientX - asideWidth); setLeftPaneWidth(e.clientX - asideWidth);
setRightPaneWidth(window.innerWidth - (e.clientX)); setRightPaneWidth(window.innerWidth - (e.clientX));
} }
}; };
const handleMouseUp = (e) => { const handleMouseUp = (e) => {
if(dragging) {
e.preventDefault(); e.preventDefault();
setDragging(false); setDragging(false);
}
}; };
const handleMouseDown = (e) => { const handleDragbarMouseDown = (e) => {
e.preventDefault(); e.preventDefault();
setDragging(true); setDragging(true);
}; };
// useEffect(() => {
// document.addEventListener('mouseup', handleMouseUp);
// document.addEventListener('mousemove', handleMouseMove);
// return () => { useEffect(() => {
// document.removeEventListener('mouseup', handleMouseUp); document.addEventListener('mouseup', handleMouseUp);
// document.removeEventListener('mousemove', handleMouseMove); document.addEventListener('mousemove', handleMouseMove);
// };
// }, [dragging, leftPaneWidth]); return () => {
document.removeEventListener('mouseup', handleMouseUp);
document.removeEventListener('mousemove', handleMouseMove);
};
}, [dragging, leftPaneWidth]);
const onUrlChange = (value) => { const onUrlChange = (value) => {
dispatch({ dispatch({
@ -119,8 +123,11 @@ const RequestTabPanel = ({dispatch, actions, collections, activeRequestTabId, re
/> />
</div> </div>
<section className="main flex flex-grow"> <section className="main flex flex-grow">
<section className="request-pane px-4"> <section className="request-pane">
<div style={{width: `${leftPaneWidth}px`, height: 'calc(100% - 5px)'}}> <div
className="px-4"
style={{width: `${leftPaneWidth}px`, height: 'calc(100% - 5px)'}}
>
{item.request.type === 'graphql' ? ( {item.request.type === 'graphql' ? (
<GraphQLRequestPane <GraphQLRequestPane
onRunQuery={runQuery} onRunQuery={runQuery}
@ -139,7 +146,7 @@ const RequestTabPanel = ({dispatch, actions, collections, activeRequestTabId, re
</div> </div>
</section> </section>
<div className="drag-request" onMouseDown={handleMouseDown}> <div className="drag-request" onMouseDown={handleDragbarMouseDown}>
</div> </div>
<section className="response-pane px-4 flex-grow"> <section className="response-pane px-4 flex-grow">

View File

@ -20,18 +20,6 @@ const Wrapper = styled.div`
} }
} }
div.drag-request {
display: flex;
width: 1px;
padding: 0;
cursor: col-resize;
background: var(--color-request-dragbar-background);
&:hover {
background: silver;
}
}
.fw-600 { .fw-600 {
font-weight: 600; font-weight: 600;
} }

View File

@ -28,6 +28,7 @@ import 'codemirror-graphql/jump';
import 'codemirror-graphql/mode'; import 'codemirror-graphql/mode';
import 'codemirror/addon/fold/foldgutter.css'; import 'codemirror/addon/fold/foldgutter.css';
import 'codemirror/addon/dialog/dialog.css';
import 'codemirror/addon/hint/show-hint.css'; import 'codemirror/addon/hint/show-hint.css';
const RequestTabPanel = dynamic(import('@grafnode/components').then(mod => mod.RequestTabPanel), { ssr: false }); const RequestTabPanel = dynamic(import('@grafnode/components').then(mod => mod.RequestTabPanel), { ssr: false });

View File

@ -4,6 +4,7 @@
--color-sidebar-collection-item-focused-indent-border: #7b8de3; --color-sidebar-collection-item-focused-indent-border: #7b8de3;
--color-sidebar-background: #f6f8fa; --color-sidebar-background: #f6f8fa;
--color-request-dragbar-background: #e2e2e2; --color-request-dragbar-background: #e2e2e2;
--color-request-dragbar-background-active: #bbb;
--color-tab-active-border: #4d4d4d; --color-tab-active-border: #4d4d4d;
--color-layout-border: #dedede; --color-layout-border: #dedede;
--color-codemirror-border: #efefef; --color-codemirror-border: #efefef;