feat: hoisted response state in the top level store

This commit is contained in:
Anoop M D
2021-12-09 22:14:49 +05:30
parent 4a576665be
commit 17e755123e
6 changed files with 155 additions and 13 deletions

View File

@ -65,6 +65,8 @@ export default function Main() {
activeRequestTabId={activeRequestTabId}
/>
<RequestTabPanel
actions={actions}
dispatch={dispatch}
collections={collections}
requestTabs={requestTabs}
activeRequestTabId={activeRequestTabId}

View File

@ -2,10 +2,12 @@ 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 RESPONSE_RECEIVED = "RESPONSE_RECEIVED";
export default {
SIDEBAR_COLLECTION_CLICK,
SIDEBAR_COLLECTION_ITEM_CLICK,
REQUEST_TAB_CLICK,
REQUEST_TAB_CLOSE
REQUEST_TAB_CLOSE,
RESPONSE_RECEIVED
};

View File

@ -30,7 +30,8 @@ const collection = {
"variables": ""
}
}
}
},
"response": null
},
{
"id": nanoid(),
@ -43,11 +44,12 @@ const collection = {
"body": {
"mimeType": "application/graphql",
"graphql": {
"query": "{\n launches {\n launch_site {\n site_id\n site_name\n site_name_long\n }\n launch_success\n }\n}",
"query": "{\n launches {\n launch_site {\n site_id\n site_name\n }\n launch_success\n }\n}",
"variables": ""
}
}
}
},
"response": null
}
]
}

View File

@ -13,20 +13,20 @@ const reducer = (state, action) => {
switch (action.type) {
case actions.SIDEBAR_COLLECTION_CLICK: {
return produce(state, (draft) => {
const collecton = find(draft.collections, (c) => c.id === action.id);
const collection = find(draft.collections, (c) => c.id === action.id);
if(collecton) {
collecton.collapsed = !collecton.collapsed;
if(collection) {
collection.collapsed = !collection.collapsed;
}
});
}
case actions.SIDEBAR_COLLECTION_ITEM_CLICK: {
return produce(state, (draft) => {
const collecton = find(draft.collections, (c) => c.id === action.collectionId);
const collection = find(draft.collections, (c) => c.id === action.collectionId);
if(collecton) {
let flattenedItems = flattenItems(collecton.items);
if(collection) {
let flattenedItems = flattenItems(collection.items);
let item = findItem(flattenedItems, action.itemId);
if(item) {
@ -40,7 +40,7 @@ const reducer = (state, action) => {
id: item.id,
name: item.name,
method: item.request.method,
collectionId: collecton.id
collectionId: collection.id
});
draft.activeRequestTabId = item.id;
}
@ -56,6 +56,21 @@ const reducer = (state, action) => {
});
}
case actions.RESPONSE_RECEIVED: {
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.response = action.response;
}
}
});
}
case actions.REQUEST_TAB_CLOSE: {
return produce(state, (draft) => {