jiti-meet/react/features/toolbox/reducer.js

242 lines
5.8 KiB
JavaScript
Raw Normal View History

2017-02-16 23:02:40 +00:00
/* @flow */
import { ReducerRegistry } from '../base/redux';
import {
2017-04-01 05:52:40 +00:00
CLEAR_TOOLBOX_TIMEOUT,
SET_DEFAULT_TOOLBOX_BUTTONS,
2017-02-16 23:02:40 +00:00
SET_SUBJECT,
SET_SUBJECT_SLIDE_IN,
SET_TOOLBAR_BUTTON,
SET_TOOLBAR_HOVERED,
SET_TOOLBOX_ALWAYS_VISIBLE,
SET_TOOLBOX_ENABLED,
2017-04-01 05:52:40 +00:00
SET_TOOLBOX_TIMEOUT,
SET_TOOLBOX_TIMEOUT_MS,
SET_TOOLBOX_VISIBLE
2017-02-16 23:02:40 +00:00
} from './actionTypes';
import defaultToolbarButtons from './defaultToolbarButtons';
2017-02-16 23:02:40 +00:00
declare var interfaceConfig: Object;
/**
2017-04-01 05:52:40 +00:00
* Returns initial state for toolbox's part of Redux store.
2017-02-16 23:02:40 +00:00
*
2017-04-01 05:52:40 +00:00
* @private
2017-02-16 23:02:40 +00:00
* @returns {{
2017-04-01 05:52:40 +00:00
* alwaysVisible: boolean,
* hovered: boolean,
2017-02-16 23:02:40 +00:00
* primaryToolbarButtons: Map,
2017-04-01 05:52:40 +00:00
* secondaryToolbarButtons: Map,
* subject: string,
* subjectSlideIn: boolean,
* timeoutID: number,
* timeoutMS: number,
* visible: boolean
2017-02-16 23:02:40 +00:00
* }}
*/
function _getInitialState() {
2017-04-01 05:52:40 +00:00
// Default toolbox timeout for mobile app.
let timeoutMS = 5000;
2017-02-16 23:02:40 +00:00
if (typeof interfaceConfig !== 'undefined'
&& interfaceConfig.INITIAL_TOOLBAR_TIMEOUT) {
2017-04-01 05:52:40 +00:00
timeoutMS = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
2017-02-16 23:02:40 +00:00
}
return {
/**
2017-04-01 05:52:40 +00:00
* The indicator which determines whether the Toolbox should always be
* visible.
2017-02-16 23:02:40 +00:00
*
* @type {boolean}
*/
alwaysVisible: false,
/**
* The indicator which determines whether the Toolbox is enabled. For
* example, modules/UI/recording/Recording.js disables the Toolbox.
*
* @type {boolean}
*/
enabled: true,
2017-02-16 23:02:40 +00:00
/**
2017-04-01 05:52:40 +00:00
* The indicator which determines whether a Toolbar in the Toolbox is
* hovered.
2017-02-16 23:02:40 +00:00
*
* @type {boolean}
*/
hovered: false,
/**
* A Map of the default buttons of the PrimaryToolbar.
*
* @type {Map}
*/
primaryToolbarButtons: new Map(),
/**
* A Map of the default buttons of the SecondaryToolbar.
*
* @type {Map}
*/
secondaryToolbarButtons: new Map(),
2017-02-16 23:02:40 +00:00
/**
2017-04-01 05:52:40 +00:00
* The text of the conference subject.
2017-02-16 23:02:40 +00:00
*
* @type {string}
*/
subject: '',
/**
2017-04-01 05:52:40 +00:00
* The indicator which determines whether the subject is sliding in.
2017-02-16 23:02:40 +00:00
*
* @type {boolean}
*/
subjectSlideIn: false,
/**
2017-04-01 05:52:40 +00:00
* A number, non-zero value which identifies the timer created by a call
* to setTimeout() with timeoutMS.
2017-02-16 23:02:40 +00:00
*
* @type {number|null}
*/
2017-04-01 05:52:40 +00:00
timeoutID: null,
2017-02-16 23:02:40 +00:00
/**
2017-04-01 05:52:40 +00:00
* The delay in milliseconds before timeoutID executes (after its
* initialization).
2017-02-16 23:02:40 +00:00
*
* @type {number}
*/
2017-04-01 05:52:40 +00:00
timeoutMS,
2017-02-16 23:02:40 +00:00
/**
2017-04-01 05:52:40 +00:00
* The indicator which determines whether the Toolbox is visible.
2017-02-16 23:02:40 +00:00
*
* @type {boolean}
*/
visible: false
};
}
ReducerRegistry.register(
2017-04-01 05:52:40 +00:00
'features/toolbox',
2017-02-16 23:02:40 +00:00
(state: Object = _getInitialState(), action: Object) => {
switch (action.type) {
2017-04-01 05:52:40 +00:00
case CLEAR_TOOLBOX_TIMEOUT:
2017-02-16 23:02:40 +00:00
return {
...state,
2017-04-01 05:52:40 +00:00
timeoutID: undefined
2017-02-16 23:02:40 +00:00
};
case SET_DEFAULT_TOOLBOX_BUTTONS: {
const { primaryToolbarButtons, secondaryToolbarButtons } = action;
return {
...state,
primaryToolbarButtons,
secondaryToolbarButtons
};
}
2017-02-16 23:02:40 +00:00
case SET_SUBJECT:
return {
...state,
subject: action.subject
};
case SET_SUBJECT_SLIDE_IN:
return {
...state,
subjectSlideIn: action.subjectSlideIn
};
case SET_TOOLBAR_BUTTON:
return _setButton(state, action);
case SET_TOOLBAR_HOVERED:
return {
...state,
hovered: action.hovered
};
case SET_TOOLBOX_ALWAYS_VISIBLE:
return {
...state,
alwaysVisible: action.alwaysVisible
};
case SET_TOOLBOX_ENABLED:
return {
...state,
enabled: action.enabled
};
2017-04-01 05:52:40 +00:00
case SET_TOOLBOX_TIMEOUT:
2017-02-16 23:02:40 +00:00
return {
...state,
2017-04-01 05:52:40 +00:00
timeoutID: action.timeoutID,
timeoutMS: action.timeoutMS
2017-02-16 23:02:40 +00:00
};
2017-04-01 05:52:40 +00:00
case SET_TOOLBOX_TIMEOUT_MS:
2017-02-16 23:02:40 +00:00
return {
...state,
2017-04-01 05:52:40 +00:00
timeoutMS: action.timeoutMS
2017-02-16 23:02:40 +00:00
};
2017-04-01 05:52:40 +00:00
case SET_TOOLBOX_VISIBLE:
2017-02-16 23:02:40 +00:00
return {
...state,
visible: action.visible
};
}
return state;
});
/**
* Sets new value of the button.
*
* @param {Object} state - Redux state.
* @param {Object} action - Dispatched action.
* @param {Object} action.button - Object describing toolbar button.
* @param {Object} action.buttonName - The name of the button.
* @private
2017-04-01 05:52:40 +00:00
* @returns {Object}
2017-02-16 23:02:40 +00:00
*/
function _setButton(state, { button, buttonName }): Object {
const buttonDefinition = defaultToolbarButtons[buttonName];
// We don't need to update if the button shouldn't be displayed
if (!buttonDefinition || !buttonDefinition.isDisplayed()) {
return {
...state
};
}
const { primaryToolbarButtons, secondaryToolbarButtons } = state;
2017-02-16 23:02:40 +00:00
let selectedButton = primaryToolbarButtons.get(buttonName);
let place = 'primaryToolbarButtons';
if (!selectedButton) {
selectedButton = secondaryToolbarButtons.get(buttonName);
place = 'secondaryToolbarButtons';
}
selectedButton = {
...selectedButton,
...button
};
const updatedToolbar = state[place].set(buttonName, selectedButton);
return {
...state,
[place]: new Map(updatedToolbar)
};
}