2021-07-13 06:50:08 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { ReducerRegistry } from '../base/redux';
|
|
|
|
|
|
|
|
import {
|
|
|
|
TOGGLE_REACTIONS_VISIBLE,
|
2021-07-20 11:31:49 +00:00
|
|
|
SET_REACTION_QUEUE,
|
|
|
|
ADD_REACTION_BUFFER,
|
|
|
|
FLUSH_REACTION_BUFFER
|
2021-07-13 06:50:08 +00:00
|
|
|
} 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,
|
|
|
|
|
|
|
|
/**
|
2021-07-20 11:31:49 +00:00
|
|
|
* An array that contains the reactions buffer to be sent.
|
2021-07-13 06:50:08 +00:00
|
|
|
*
|
2021-07-20 11:31:49 +00:00
|
|
|
* @type {Array}
|
2021-07-13 06:50:08 +00:00
|
|
|
*/
|
2021-07-20 11:31:49 +00:00
|
|
|
buffer: [],
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
};
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
case ADD_REACTION_BUFFER:
|
2021-07-13 06:50:08 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2021-07-20 11:31:49 +00:00
|
|
|
buffer: action.buffer,
|
2021-07-13 06:50:08 +00:00
|
|
|
timeoutID: action.timeoutID
|
|
|
|
};
|
|
|
|
|
2021-07-20 11:31:49 +00:00
|
|
|
case FLUSH_REACTION_BUFFER:
|
2021-07-13 06:50:08 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2021-07-20 11:31:49 +00:00
|
|
|
buffer: [],
|
2021-07-13 06:50:08 +00:00
|
|
|
timeoutID: null
|
|
|
|
};
|
|
|
|
|
|
|
|
case SET_REACTION_QUEUE: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
queue: action.value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|