2021-09-23 09:20:11 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-09-23 14:39:05 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2021-09-23 09:20:11 +00:00
|
|
|
import {
|
|
|
|
SET_TOOLBOX_ENABLED,
|
2021-10-25 09:16:03 +00:00
|
|
|
SET_TOOLBOX_VISIBLE,
|
|
|
|
TOGGLE_TOOLBOX_VISIBLE
|
2021-09-23 09:20:11 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables/disables the toolbox.
|
|
|
|
*
|
|
|
|
* @param {boolean} enabled - True to enable the toolbox or false to disable it.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_TOOLBOX_ENABLED,
|
|
|
|
* enabled: boolean
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function setToolboxEnabled(enabled: boolean): Object {
|
|
|
|
return {
|
|
|
|
type: SET_TOOLBOX_ENABLED,
|
|
|
|
enabled
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows/hides the toolbox.
|
|
|
|
*
|
|
|
|
* @param {boolean} visible - True to show the toolbox or false to hide it.
|
2021-09-23 14:39:05 +00:00
|
|
|
* @returns {Function}
|
2021-09-23 09:20:11 +00:00
|
|
|
*/
|
|
|
|
export function setToolboxVisible(visible: boolean): Object {
|
2021-09-23 14:39:05 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
|
|
|
const { toolbarConfig: { alwaysVisible } } = getState()['features/base/config'];
|
|
|
|
|
|
|
|
if (!visible && alwaysVisible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: SET_TOOLBOX_VISIBLE,
|
|
|
|
visible
|
|
|
|
});
|
2021-09-23 09:20:11 +00:00
|
|
|
};
|
|
|
|
}
|
2021-10-25 09:16:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to toggle the toolbox visibility.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function toggleToolboxVisible() {
|
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
|
|
|
const state = getState();
|
|
|
|
const { toolbarConfig: { alwaysVisible } } = state['features/base/config'];
|
|
|
|
const { visible } = state['features/toolbox'];
|
|
|
|
|
|
|
|
if (visible && alwaysVisible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: TOGGLE_TOOLBOX_VISIBLE
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|