From 4c679b6d839351f012e14ff3c439fe5bc44d6fd0 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Mon, 6 Apr 2020 16:03:47 -0700 Subject: [PATCH] Removed initial conversations from reducer. --- .../src/redux/messaging/messaging.reducer.js | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/client/src/redux/messaging/messaging.reducer.js b/client/src/redux/messaging/messaging.reducer.js index a66d3aadd..7fcfaa2b7 100644 --- a/client/src/redux/messaging/messaging.reducer.js +++ b/client/src/redux/messaging/messaging.reducer.js @@ -4,22 +4,22 @@ const INITIAL_STATE = { visible: false, unread: 0, conversations: [ - { - phone_num: "6049992002", - id: "519ba10d-6467-4fa5-9c22-59ae891edeb6", - open: false, - isSending: false, - sendingError: null - }, - { - phone_num: "6049992991", - id: "ab57deba-eeb9-40db-b5ae-23f3ce8d7c7b", - open: false, - isSending: false, - sendingError: null - } + // { + // phone_num: "6049992002", + // id: "519ba10d-6467-4fa5-9c22-59ae891edeb6", + // open: false, + // isSending: false, + // sendingError: null + // }, + // { + // phone_num: "6049992991", + // id: "ab57deba-eeb9-40db-b5ae-23f3ce8d7c7b", + // open: false, + // isSending: false, + // sendingError: null + // } ], - error: null + error: null, }; const messagingReducer = (state = INITIAL_STATE, action) => { @@ -27,47 +27,49 @@ const messagingReducer = (state = INITIAL_STATE, action) => { case MessagingActionTypes.TOGGLE_CHAT_VISIBLE: return { ...state, - visible: !state.visible + visible: !state.visible, }; case MessagingActionTypes.SET_CHAT_VISIBLE: return { ...state, - visible: true + visible: true, }; case MessagingActionTypes.SEND_MESSAGE: return { ...state, - conversations: state.conversations.map(c => + conversations: state.conversations.map((c) => c.id === action.payload.conversationid ? { ...c, isSending: true } : c - ) + ), }; case MessagingActionTypes.SEND_MESSAGE_SUCCESS: return { ...state, - conversations: state.conversations.map(c => + conversations: state.conversations.map((c) => c.id === action.payload.conversationid ? { ...c, isSending: false } : c - ) + ), }; case MessagingActionTypes.SEND_MESSAGE_FAILURE: return { ...state, - conversations: state.conversations.map(c => + conversations: state.conversations.map((c) => c.id === action.payload.conversationid ? { ...c, isSending: false, sendingError: action.payload.error } : c - ) + ), }; case MessagingActionTypes.OPEN_CONVERSATION: if ( - state.conversations.find(c => c.phone_num === action.payload.phone_num) + state.conversations.find( + (c) => c.phone_num === action.payload.phone_num + ) ) return { ...state, - conversations: state.conversations.map(c => + conversations: state.conversations.map((c) => c.phone_num === action.payload.phone_num ? { ...c, open: true } : c - ) + ), }; else return { @@ -79,23 +81,23 @@ const messagingReducer = (state = INITIAL_STATE, action) => { id: action.payload.id, open: true, isSending: false, - sendingError: null - } - ] + sendingError: null, + }, + ], }; case MessagingActionTypes.CLOSE_CONVERSATION: return { ...state, conversations: state.conversations.filter( - c => c.phone_num !== action.payload - ) + (c) => c.phone_num !== action.payload + ), }; case MessagingActionTypes.TOGGLE_CONVERSATION_VISIBLE: return { ...state, - conversations: state.conversations.map(c => + conversations: state.conversations.map((c) => c.id === action.payload ? { ...c, open: !c.open } : c - ) + ), }; default: