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"> <div className="flex items-center flex-grow input-container h-full">
<input <input
className="px-3 w-full" 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> </div>
<button <button

View File

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