Removed initial conversations from reducer.
This commit is contained in:
@@ -4,22 +4,22 @@ const INITIAL_STATE = {
|
|||||||
visible: false,
|
visible: false,
|
||||||
unread: 0,
|
unread: 0,
|
||||||
conversations: [
|
conversations: [
|
||||||
{
|
// {
|
||||||
phone_num: "6049992002",
|
// phone_num: "6049992002",
|
||||||
id: "519ba10d-6467-4fa5-9c22-59ae891edeb6",
|
// id: "519ba10d-6467-4fa5-9c22-59ae891edeb6",
|
||||||
open: false,
|
// open: false,
|
||||||
isSending: false,
|
// isSending: false,
|
||||||
sendingError: null
|
// sendingError: null
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
phone_num: "6049992991",
|
// phone_num: "6049992991",
|
||||||
id: "ab57deba-eeb9-40db-b5ae-23f3ce8d7c7b",
|
// id: "ab57deba-eeb9-40db-b5ae-23f3ce8d7c7b",
|
||||||
open: false,
|
// open: false,
|
||||||
isSending: false,
|
// isSending: false,
|
||||||
sendingError: null
|
// sendingError: null
|
||||||
}
|
// }
|
||||||
],
|
],
|
||||||
error: null
|
error: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const messagingReducer = (state = INITIAL_STATE, action) => {
|
const messagingReducer = (state = INITIAL_STATE, action) => {
|
||||||
@@ -27,47 +27,49 @@ const messagingReducer = (state = INITIAL_STATE, action) => {
|
|||||||
case MessagingActionTypes.TOGGLE_CHAT_VISIBLE:
|
case MessagingActionTypes.TOGGLE_CHAT_VISIBLE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
visible: !state.visible
|
visible: !state.visible,
|
||||||
};
|
};
|
||||||
case MessagingActionTypes.SET_CHAT_VISIBLE:
|
case MessagingActionTypes.SET_CHAT_VISIBLE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
visible: true
|
visible: true,
|
||||||
};
|
};
|
||||||
case MessagingActionTypes.SEND_MESSAGE:
|
case MessagingActionTypes.SEND_MESSAGE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
conversations: state.conversations.map(c =>
|
conversations: state.conversations.map((c) =>
|
||||||
c.id === action.payload.conversationid ? { ...c, isSending: true } : c
|
c.id === action.payload.conversationid ? { ...c, isSending: true } : c
|
||||||
)
|
),
|
||||||
};
|
};
|
||||||
case MessagingActionTypes.SEND_MESSAGE_SUCCESS:
|
case MessagingActionTypes.SEND_MESSAGE_SUCCESS:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
conversations: state.conversations.map(c =>
|
conversations: state.conversations.map((c) =>
|
||||||
c.id === action.payload.conversationid
|
c.id === action.payload.conversationid
|
||||||
? { ...c, isSending: false }
|
? { ...c, isSending: false }
|
||||||
: c
|
: c
|
||||||
)
|
),
|
||||||
};
|
};
|
||||||
case MessagingActionTypes.SEND_MESSAGE_FAILURE:
|
case MessagingActionTypes.SEND_MESSAGE_FAILURE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
conversations: state.conversations.map(c =>
|
conversations: state.conversations.map((c) =>
|
||||||
c.id === action.payload.conversationid
|
c.id === action.payload.conversationid
|
||||||
? { ...c, isSending: false, sendingError: action.payload.error }
|
? { ...c, isSending: false, sendingError: action.payload.error }
|
||||||
: c
|
: c
|
||||||
)
|
),
|
||||||
};
|
};
|
||||||
case MessagingActionTypes.OPEN_CONVERSATION:
|
case MessagingActionTypes.OPEN_CONVERSATION:
|
||||||
if (
|
if (
|
||||||
state.conversations.find(c => c.phone_num === action.payload.phone_num)
|
state.conversations.find(
|
||||||
|
(c) => c.phone_num === action.payload.phone_num
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
conversations: state.conversations.map(c =>
|
conversations: state.conversations.map((c) =>
|
||||||
c.phone_num === action.payload.phone_num ? { ...c, open: true } : c
|
c.phone_num === action.payload.phone_num ? { ...c, open: true } : c
|
||||||
)
|
),
|
||||||
};
|
};
|
||||||
else
|
else
|
||||||
return {
|
return {
|
||||||
@@ -79,23 +81,23 @@ const messagingReducer = (state = INITIAL_STATE, action) => {
|
|||||||
id: action.payload.id,
|
id: action.payload.id,
|
||||||
open: true,
|
open: true,
|
||||||
isSending: false,
|
isSending: false,
|
||||||
sendingError: null
|
sendingError: null,
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
case MessagingActionTypes.CLOSE_CONVERSATION:
|
case MessagingActionTypes.CLOSE_CONVERSATION:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
conversations: state.conversations.filter(
|
conversations: state.conversations.filter(
|
||||||
c => c.phone_num !== action.payload
|
(c) => c.phone_num !== action.payload
|
||||||
)
|
),
|
||||||
};
|
};
|
||||||
case MessagingActionTypes.TOGGLE_CONVERSATION_VISIBLE:
|
case MessagingActionTypes.TOGGLE_CONVERSATION_VISIBLE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
conversations: state.conversations.map(c =>
|
conversations: state.conversations.map((c) =>
|
||||||
c.id === action.payload ? { ...c, open: !c.open } : c
|
c.id === action.payload ? { ...c, open: !c.open } : c
|
||||||
)
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user