import React, { useState, useEffect } from 'react'; import get from 'lodash/get'; import { useDispatch } from 'react-redux'; import { requestUrlChanged, updateRequestMethod } from 'providers/ReduxStore/slices/collections'; import { saveRequest } from 'providers/ReduxStore/slices/collections/actions'; import HttpMethodSelector from './HttpMethodSelector'; import { useTheme } from 'providers/Theme'; import SendIcon from 'components/Icons/Send'; import SingleLineEditor from 'components/SingleLineEditor'; import StyledWrapper from './StyledWrapper'; const QueryUrl = ({ item, collection, handleRun }) => { const { theme, storedTheme } = useTheme(); const dispatch = useDispatch(); const method = item.draft ? get(item, 'draft.request.method') : get(item, 'request.method'); const url = item.draft ? get(item, 'draft.request.url') : get(item, 'request.url'); const [methodSelectorWidth, setMethodSelectorWidth] = useState(90); useEffect(() => { const el = document.querySelector('.method-selector-container'); setMethodSelectorWidth(el.offsetWidth); }, [method]); const onSave = () => dispatch(saveRequest(item.uid, collection.uid)); const onUrlChange = (value) => { dispatch( requestUrlChanged({ itemUid: item.uid, collectionUid: collection.uid, url: value }) ); }; const onMethodSelect = (verb) => { dispatch( updateRequestMethod({ method: verb, itemUid: item.uid, collectionUid: collection.uid }) ); }; return (
onUrlChange(newValue)} onRun={handleRun} collection={collection} />
); }; export default QueryUrl;