12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import isEqual from 'lodash.isequal';
- import { createReducer } from '@reduxjs/toolkit';
- import { IChatPayload } from '../../../typescript/redux/chat/interfaces';
- import { TChat} from '../../../typescript/redux/chat/types';
- import {
- actionSelectChat,
- actionGetChatById,
- actionRemoveChat
- } from '../action';
- const initialState: TChat = {
- name: '',
- lastName: '',
- originalName: '',
- originalLastName: '',
- avatarUrl: '',
- avatarsArr: [],
- color: '',
- online: '',
- lastMessage: '',
- lastMessageCreatedAt:'',
- mute: false,
- sort:false,
- seen: 0,
- seenCompanion: 0,
- total: 0,
- watched: false,
- typing: false,
- number: '',
- country: '',
- pinned: false,
- _id: '',
- companionId: '',
- owner: '',
- createdAt: '',
- updatedAt: '',
- __v: 0,
- }
- const reducerChat = createReducer(initialState, {
- [actionSelectChat.type]: (state, { payload }: IChatPayload) => {
- if (isEqual(state, payload) === false) return payload
- return state;
- },
- [actionGetChatById.type]: (state, { payload }: IChatPayload) => {
- if (isEqual(state, payload) === false) return payload
- return state;
- },
- [actionRemoveChat.type]: (_state,_payload) => {
- return initialState
- },
- });
- export default reducerChat;
|