src/store/reducers/Chat.ts
import { ChatActions, ChatActionTypes } from "store/actions/Chat";
import { ChatSettings, ChatTypes } from "types/chat";
export type ChatState = {
isChatSidebarVisible: boolean;
settings: ChatSettings;
};
const initialChatState: ChatState = {
isChatSidebarVisible: false,
settings: {
openedChatType: ChatTypes.VENUE_CHAT,
},
};
export const chatReducer = (
state = initialChatState,
action: ChatActions
): ChatState => {
switch (action.type) {
case ChatActionTypes.SET_CHAT_SIDEBAR_VISIBILITY:
const { isVisible: isChatSidebarVisible } = action.payload;
return { ...state, isChatSidebarVisible };
case ChatActionTypes.SET_VENUE_CHAT_TAB_OPENED: {
const { openedChatType } = action.payload;
return {
...state,
settings: { openedChatType },
};
}
case ChatActionTypes.SET_PRIVATE_CHAT_TAB_OPENED: {
const { openedChatType, recipient } = action.payload;
return {
...state,
settings: { openedChatType, recipient },
};
}
default:
return state;
}
};