Added chat support

This commit is contained in:
Håvar Aambø Fosstveit
2018-03-01 16:19:37 +01:00
parent 9a7e149c35
commit 494250153e
18 changed files with 617 additions and 7 deletions
+31
View File
@@ -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;
+45
View File
@@ -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;
+10
View File
@@ -0,0 +1,10 @@
export function createNewMessage(text, sender, name)
{
return {
type : 'message',
text,
time : Date.now(),
name,
sender
};
}
+5 -1
View File
@@ -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;