123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- // @flow
-
- import { ReducerRegistry } from '../base/redux';
-
- import {
- TOGGLE_REACTIONS_VISIBLE,
- SET_REACTIONS_MESSAGE,
- CLEAR_REACTIONS_MESSAGE,
- SET_REACTION_QUEUE
- } from './actionTypes';
-
- /**
- * Returns initial state for reactions' part of Redux store.
- *
- * @private
- * @returns {{
- * visible: boolean,
- * message: string,
- * timeoutID: number,
- * queue: Array
- * }}
- */
- function _getInitialState() {
- return {
- /**
- * The indicator that determines whether the reactions menu is visible.
- *
- * @type {boolean}
- */
- visible: false,
-
- /**
- * A string that contains the message to be added to the chat.
- *
- * @type {string}
- */
- message: '',
-
- /**
- * A number, non-zero value which identifies the timer created by a call
- * to setTimeout().
- *
- * @type {number|null}
- */
- timeoutID: null,
-
- /**
- * The array of reactions to animate
- *
- * @type {Array}
- */
- queue: []
- };
- }
-
- ReducerRegistry.register(
- 'features/reactions',
- (state: Object = _getInitialState(), action: Object) => {
- switch (action.type) {
-
- case TOGGLE_REACTIONS_VISIBLE:
- return {
- ...state,
- visible: !state.visible
- };
-
- case SET_REACTIONS_MESSAGE:
- return {
- ...state,
- message: action.message,
- timeoutID: action.timeoutID
- };
-
- case CLEAR_REACTIONS_MESSAGE:
- return {
- ...state,
- message: '',
- timeoutID: null
- };
-
- case SET_REACTION_QUEUE: {
- return {
- ...state,
- queue: action.value
- };
- }
- }
-
- return state;
- });
|