sparkletown/sparkle

View on GitHub
src/store/reducers/Chat.ts

Summary

Maintainability
A
0 mins
Test Coverage
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;
  }
};