feat: moved the logic up for managing request url

This commit is contained in:
Anoop M D 2022-01-18 21:41:27 +05:30
parent 83d33b604a
commit 2f222aebde
4 changed files with 37 additions and 12 deletions

View File

@ -85,7 +85,8 @@ const QueryUrl = ({value, onChange, handleRun, collections}) => {
<div className="flex items-center flex-grow input-container h-full">
<input
className="px-3 w-full"
type="text" value={value} onChange={(event) => onChange(event.target.value)}
type="text" defaultValue={value}
onChange={(event) => onChange(event.target.value)}
/>
</div>
<button

View File

@ -18,7 +18,6 @@ const RequestTabPanel = ({dispatch, actions, collections, activeRequestTabId, re
}
let asideWidth = 200;
let [url, setUrl] = useState('https://api.spacex.land/graphql');
let {
schema
} = useGraphqlSchema('https://api.spacex.land/graphql');
@ -41,17 +40,25 @@ const RequestTabPanel = ({dispatch, actions, collections, activeRequestTabId, re
e.preventDefault();
setDragging(true);
};
useEffect(() => {
document.addEventListener('mouseup', handleMouseUp);
document.addEventListener('mousemove', handleMouseMove);
// useEffect(() => {
// document.addEventListener('mouseup', handleMouseUp);
// document.addEventListener('mousemove', handleMouseMove);
return () => {
document.removeEventListener('mouseup', handleMouseUp);
document.removeEventListener('mousemove', handleMouseMove);
};
}, [dragging, leftPaneWidth]);
// 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 onUrlChange = (value) => setUrl(value);
const onQueryChange = (value) => setQuery(value);
if(!activeRequestTabId) {
@ -97,7 +104,7 @@ const RequestTabPanel = ({dispatch, actions, collections, activeRequestTabId, re
>
<div className="pt-2 text-gray-600">{item.name}</div>
<QueryUrl
value = {url}
value = {item.request.url}
onChange={onUrlChange}
handleRun={runQuery}
collections={collections}

View File

@ -2,6 +2,7 @@ const SIDEBAR_COLLECTION_CLICK = "SIDEBAR_COLLECTION_CLICK";
const SIDEBAR_COLLECTION_ITEM_CLICK = "SIDEBAR_COLLECTION_ITEM_CLICK";
const REQUEST_TAB_CLICK = "REQUEST_TAB_CLICK";
const REQUEST_TAB_CLOSE = "REQUEST_TAB_CLOSE";
const REQUEST_URL_CHANGED = "REQUEST_URL_CHANGED";
const RESPONSE_RECEIVED = "RESPONSE_RECEIVED";
const SEND_REQUEST = "SEND_REQUEST";
const SENDING_REQUEST = "SENDING_REQUEST";
@ -14,6 +15,7 @@ export default {
SIDEBAR_COLLECTION_ITEM_CLICK,
REQUEST_TAB_CLICK,
REQUEST_TAB_CLOSE,
REQUEST_URL_CHANGED,
RESPONSE_RECEIVED,
SEND_REQUEST,
SENDING_REQUEST,

View File

@ -58,6 +58,21 @@ const reducer = (state, action) => {
});
}
case actions.REQUEST_URL_CHANGED: {
return produce(state, (draft) => {
const collection = find(draft.collections, (c) => c.id === action.collectionId);
if(collection) {
let flattenedItems = flattenItems(collection.items);
let item = findItem(flattenedItems, action.requestTab.id);
if(item) {
item.request.url = action.url;
}
}
});
}
case actions.ADD_NEW_HTTP_REQUEST: {
return produce(state, (draft) => {
const uid = nanoid();