Removed initial conversations from reducer.

This commit is contained in:
Patrick Fic
2020-04-06 16:03:47 -07:00
parent 019fd90170
commit 4c679b6d83

View File

@@ -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: