2019-10-07 20:56:30 +00:00
|
|
|
import { USERS_TYPING } from '../actions/actionsTypes';
|
2022-02-28 18:00:47 +00:00
|
|
|
import { TApplicationActions } from '../definitions';
|
2019-10-07 20:56:30 +00:00
|
|
|
|
2022-02-28 18:00:47 +00:00
|
|
|
export type IUsersTyping = string[];
|
2019-10-07 20:56:30 +00:00
|
|
|
|
2022-02-28 18:00:47 +00:00
|
|
|
export const initialState: IUsersTyping = [];
|
|
|
|
|
|
|
|
export default function usersTyping(state = initialState, action: TApplicationActions): IUsersTyping {
|
2019-10-07 20:56:30 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|