import React, { useState, useEffect } from 'react'; import find from 'lodash/find'; import QueryUrl from '../QueryUrl'; import GraphQLRequestPane from '../GraphQLRequestPane'; import HttpRequestPane from '../HttpRequestPane'; import ResponsePane from '../ResponsePane'; import Welcome from '../Welcome'; import { flattenItems, findItem } from '../../utils'; import useGraphqlSchema from '../../hooks/useGraphqlSchema'; import StyledWrapper from './StyledWrapper'; const RequestTabPanel = ({dispatch, actions, collections, activeRequestTabId, requestTabs}) => { if(typeof window == 'undefined') { return
; } let asideWidth = 270; let { schema } = useGraphqlSchema('https://api.spacex.land/graphql'); const [leftPaneWidth, setLeftPaneWidth] = useState((window.innerWidth - asideWidth)/2 - 10); // 10 is for dragbar const [rightPaneWidth, setRightPaneWidth] = useState((window.innerWidth - asideWidth)/2); const [dragging, setDragging] = useState(false); const handleMouseMove = (e) => { if(dragging) { e.preventDefault(); setLeftPaneWidth(e.clientX - asideWidth); setRightPaneWidth(window.innerWidth - (e.clientX)); } }; const handleMouseUp = (e) => { if(dragging) { e.preventDefault(); setDragging(false); } }; const handleDragbarMouseDown = (e) => { e.preventDefault(); setDragging(true); }; useEffect(() => { document.addEventListener('mouseup', handleMouseUp); document.addEventListener('mousemove', handleMouseMove); return () => { document.removeEventListener('mouseup', handleMouseUp); document.removeEventListener('mousemove', handleMouseMove); }; }, [dragging, leftPaneWidth]); const onUrlChange = (value) => { dispatch({ type: actions.REQUEST_URL_CHANGED, url: value, requestTab: focusedTab, collectionId: collection ? collection.id : null }); }; const onGraphqlQueryChange = (value) => { dispatch({ type: actions.REQUEST_GQL_QUERY_CHANGED, query: value, requestTab: focusedTab, collectionId: collection ? collection.id : null }); }; if(!activeRequestTabId) { return (