Ajout notifications

This commit is contained in:
2020-02-19 13:19:04 +01:00
parent 7d57d51f07
commit d1f78689b8
8 changed files with 96 additions and 4 deletions

View File

@ -0,0 +1,32 @@
import { ADD_MESSAGE, REMOVE_OLDEST_MESSAGE } from "../actions/message.actions";
const initialState = {
sortedByTimestamp: []
};
export function messagesReducer(state = initialState, action) {
switch(action.type) {
case ADD_MESSAGE:
return handleAddMessage(state, action);
case REMOVE_OLDEST_MESSAGE:
return handleRemoveOldestMessage(state, action);
};
return state;
}
function handleAddMessage(state, action) {
return {
...state,
sortedByTimestamp: [
{ ts: Date.now(), text: action.text, type: action.messageType },
...state.sortedByTimestamp
]
}
};
function handleRemoveOldestMessage(state, action) {
return {
...state,
sortedByTimestamp: state.sortedByTimestamp.slice(0, -1)
}
};