Added chat support
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
const initialState =
|
||||
{
|
||||
showChat : false,
|
||||
disabledInput : false,
|
||||
badge : 0
|
||||
};
|
||||
|
||||
const chatbehavior = (state = initialState, action) =>
|
||||
{
|
||||
switch (action.type)
|
||||
{
|
||||
case 'TOGGLE_CHAT':
|
||||
{
|
||||
const showChat = !state.showChat;
|
||||
|
||||
return { ...state, showChat };
|
||||
}
|
||||
|
||||
case 'TOGGLE_INPUT_DISABLED':
|
||||
{
|
||||
const disabledInput = !state.disabledInput;
|
||||
|
||||
return { ...state, disabledInput };
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default chatbehavior;
|
||||
@@ -0,0 +1,45 @@
|
||||
import
|
||||
{
|
||||
createNewMessage
|
||||
} from './helper';
|
||||
|
||||
const initialState = [];
|
||||
|
||||
const chatmessages = (state = initialState, action) =>
|
||||
{
|
||||
switch (action.type)
|
||||
{
|
||||
case 'ADD_NEW_USER_MESSAGE':
|
||||
{
|
||||
const { text } = action.payload;
|
||||
|
||||
const message = createNewMessage(text, 'client', 'Me');
|
||||
|
||||
return [ ...state, message ];
|
||||
}
|
||||
|
||||
case 'ADD_NEW_RESPONSE_MESSAGE':
|
||||
{
|
||||
const { message } = action.payload;
|
||||
|
||||
return [ ...state, message ];
|
||||
}
|
||||
|
||||
case 'ADD_CHAT_HISTORY':
|
||||
{
|
||||
const { chatHistory } = action.payload;
|
||||
|
||||
return [ ...state, ...chatHistory ];
|
||||
}
|
||||
|
||||
case 'DROP_MESSAGES':
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default chatmessages;
|
||||
@@ -0,0 +1,10 @@
|
||||
export function createNewMessage(text, sender, name)
|
||||
{
|
||||
return {
|
||||
type : 'message',
|
||||
text,
|
||||
time : Date.now(),
|
||||
name,
|
||||
sender
|
||||
};
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import producers from './producers';
|
||||
import peers from './peers';
|
||||
import consumers from './consumers';
|
||||
import notifications from './notifications';
|
||||
import chatmessages from './chatmessages';
|
||||
import chatbehavior from './chatbehavior';
|
||||
|
||||
const reducers = combineReducers(
|
||||
{
|
||||
@@ -13,7 +15,9 @@ const reducers = combineReducers(
|
||||
producers,
|
||||
peers,
|
||||
consumers,
|
||||
notifications
|
||||
notifications,
|
||||
chatmessages,
|
||||
chatbehavior
|
||||
});
|
||||
|
||||
export default reducers;
|
||||
|
||||
Reference in New Issue
Block a user