feat: reducer and actions for creating a collection

This commit is contained in:
Anoop M D 2022-01-23 17:13:30 +05:30
parent efaa9aed21
commit 2431c0ac03
3 changed files with 18 additions and 0 deletions

View File

@ -25,6 +25,10 @@ const Sidebar = ({collections, actions, dispatch, activeRequestTabId}) => {
const handleConfirm = (values) => {
console.log(values);
dispatch({
name: values.collectionName,
type: actions.COLLECTION_CREATE
});
setModalOpen(false);
};

View File

@ -1,5 +1,6 @@
const SIDEBAR_COLLECTION_CLICK = "SIDEBAR_COLLECTION_CLICK";
const SIDEBAR_COLLECTION_ITEM_CLICK = "SIDEBAR_COLLECTION_ITEM_CLICK";
const COLLECTION_CREATE = "COLLECTION_CREATE";
const REQUEST_TAB_CLICK = "REQUEST_TAB_CLICK";
const REQUEST_TAB_CLOSE = "REQUEST_TAB_CLOSE";
const REQUEST_URL_CHANGED = "REQUEST_URL_CHANGED";
@ -14,6 +15,7 @@ const ADD_NEW_GQL_REQUEST = "ADD_NEW_GQL_REQUEST";
export default {
SIDEBAR_COLLECTION_CLICK,
SIDEBAR_COLLECTION_ITEM_CLICK,
COLLECTION_CREATE,
REQUEST_TAB_CLICK,
REQUEST_TAB_CLOSE,
REQUEST_URL_CHANGED,

View File

@ -52,6 +52,18 @@ const reducer = (state, action) => {
});
}
case actions.COLLECTION_CREATE: {
return produce(state, (draft) => {
// todo: collection names must be unique across a user account
draft.collections = draft.collections || [];
draft.collections.push({
id: nanoid(),
name: action.name,
items: []
});
});
}
case actions.REQUEST_TAB_CLICK: {
return produce(state, (draft) => {
draft.activeRequestTabId = action.requestTab.id;