verdnatura-chat/app/reducers/usersTyping.ts

23 lines
647 B
TypeScript
Raw Normal View History

import { USERS_TYPING } from '../actions/actionsTypes';
2022-02-28 18:00:47 +00:00
import { TApplicationActions } from '../definitions';
2022-02-28 18:00:47 +00:00
export type IUsersTyping = string[];
2022-02-28 18:00:47 +00:00
export const initialState: IUsersTyping = [];
export default function usersTyping(state = initialState, action: TApplicationActions): IUsersTyping {
switch (action.type) {
case USERS_TYPING.ADD:
if (state.findIndex(item => item === action.username) === -1) {
return [...state, action.username];
}
return state;
case USERS_TYPING.REMOVE:
return state.filter(item => item !== action.username);
case USERS_TYPING.CLEAR:
return initialState;
default:
return state;
}
}