feat(toolbox): move OverflowMenu show logic to redux

This commit is contained in:
Saúl Ibarra Corretgé 2018-04-20 13:24:14 +02:00 committed by Lyubo Marinov
parent a2834a2495
commit 9a3effe97a
5 changed files with 63 additions and 33 deletions

View File

@ -29,6 +29,16 @@ export const FULL_SCREEN_CHANGED = Symbol('FULL_SCREEN_CHANGED');
*/ */
export const SET_FULL_SCREEN = Symbol('SET_FULL_SCREEN'); export const SET_FULL_SCREEN = Symbol('SET_FULL_SCREEN');
/**
* The type of the (redux) action which shows/hides the OverflowMenu.
*
* {
* type: SET_OVERFLOW_MENU_VISIBLE,
* visible: boolean
* }
*/
export const SET_OVERFLOW_MENU_VISIBLE = Symbol('SET_OVERFLOW_MENU_VISIBLE');
/** /**
* The type of the action which sets the indicator which determiens whether a * The type of the action which sets the indicator which determiens whether a
* fToolbar in the Toolbox is hovered. * fToolbar in the Toolbox is hovered.

View File

@ -2,6 +2,7 @@
import { import {
CLEAR_TOOLBOX_TIMEOUT, CLEAR_TOOLBOX_TIMEOUT,
SET_OVERFLOW_MENU_VISIBLE,
SET_TOOLBAR_HOVERED, SET_TOOLBAR_HOVERED,
SET_TOOLBOX_ALWAYS_VISIBLE, SET_TOOLBOX_ALWAYS_VISIBLE,
SET_TOOLBOX_ENABLED, SET_TOOLBOX_ENABLED,
@ -24,6 +25,22 @@ export function clearToolboxTimeout(): Object {
}; };
} }
/**
* Shows/hides the overflow menu.
*
* @param {boolean} visible - True to show it or false to hide it.
* @returns {{
* type: SET_OVERFLOW_MENU_VISIBLE,
* visible: boolean
* }}
*/
export function setOverflowMenuVisible(visible: boolean): Object {
return {
type: SET_OVERFLOW_MENU_VISIBLE,
visible
};
}
/** /**
* Signals that toolbar is hovered value should be changed. * Signals that toolbar is hovered value should be changed.
* *

View File

@ -2,6 +2,7 @@ import InlineDialog from '@atlaskit/inline-dialog';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { createToolbarEvent, sendAnalytics } from '../../analytics';
import { translate } from '../../base/i18n'; import { translate } from '../../base/i18n';
import ToolbarButton from './ToolbarButton'; import ToolbarButton from './ToolbarButton';
@ -100,6 +101,8 @@ class OverflowMenuButton extends Component {
* @returns {void} * @returns {void}
*/ */
_onToggleDialogVisibility() { _onToggleDialogVisibility() {
sendAnalytics(createToolbarEvent('overflow'));
this.props.onVisibilityChange(!this.props.isOpen); this.props.onVisibilityChange(!this.props.isOpen);
} }
} }

View File

@ -36,7 +36,11 @@ import {
VideoQualityDialog VideoQualityDialog
} from '../../video-quality'; } from '../../video-quality';
import { setFullScreen, setToolbarHovered } from '../actions'; import {
setFullScreen,
setOverflowMenuVisible,
setToolbarHovered
} from '../actions';
import OverflowMenuButton from './OverflowMenuButton'; import OverflowMenuButton from './OverflowMenuButton';
import OverflowMenuItem from './OverflowMenuItem'; import OverflowMenuItem from './OverflowMenuItem';
@ -118,6 +122,11 @@ type Props = {
*/ */
_localParticipantID: String, _localParticipantID: String,
/**
* Whether or not the overflow menu is visible.
*/
_overflowMenuVisible: boolean,
/** /**
* Whether or not the local participant's hand is raised. * Whether or not the local participant's hand is raised.
*/ */
@ -160,14 +169,6 @@ type Props = {
t: Function t: Function
} }
type State = {
/**
* Whether or not the overflow menu is visible.
*/
showOverflowMenu: boolean
}
declare var APP: Object; declare var APP: Object;
declare var interfaceConfig: Object; declare var interfaceConfig: Object;
@ -176,13 +177,9 @@ declare var interfaceConfig: Object;
* *
* @extends Component * @extends Component
*/ */
class Toolbox extends Component<Props, State> { class Toolbox extends Component<Props> {
_visibleButtons: Object; _visibleButtons: Object;
state = {
showOverflowMenu: false
}
/** /**
* Initializes a new {@code Toolbox} instance. * Initializes a new {@code Toolbox} instance.
* *
@ -282,11 +279,11 @@ class Toolbox extends Component<Props, State> {
*/ */
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
// Ensure the dialog is closed when the toolbox becomes hidden. // Ensure the dialog is closed when the toolbox becomes hidden.
if (this.state.showOverflowMenu && !nextProps._visible) { if (this.props._overflowMenuVisible && !nextProps._visible) {
this._onSetOverflowVisible(false); this._onSetOverflowVisible(false);
} }
if (this.state.showOverflowMenu if (this.props._overflowMenuVisible
&& !this.props._dialog && !this.props._dialog
&& nextProps._dialog) { && nextProps._dialog) {
this._onSetOverflowVisible(false); this._onSetOverflowVisible(false);
@ -315,6 +312,7 @@ class Toolbox extends Component<Props, State> {
const { const {
_chatOpen, _chatOpen,
_hideInviteButton, _hideInviteButton,
_overflowMenuVisible,
_raisedHand, _raisedHand,
_visible, _visible,
t t
@ -373,7 +371,7 @@ class Toolbox extends Component<Props, State> {
{ this._shouldShowButton('info') && <InfoDialogButton /> } { this._shouldShowButton('info') && <InfoDialogButton /> }
{ overflowHasItems { overflowHasItems
&& <OverflowMenuButton && <OverflowMenuButton
isOpen = { this.state.showOverflowMenu } isOpen = { _overflowMenuVisible }
onVisibilityChange = { this._onSetOverflowVisible }> onVisibilityChange = { this._onSetOverflowVisible }>
<ul <ul
aria-label = 'Overflow menu' aria-label = 'Overflow menu'
@ -555,7 +553,7 @@ class Toolbox extends Component<Props, State> {
* @returns {void} * @returns {void}
*/ */
_onSetOverflowVisible(visible) { _onSetOverflowVisible(visible) {
this.setState({ showOverflowMenu: visible }); this.props.dispatch(setOverflowMenuVisible(visible));
} }
_onShortcutToggleChat: () => void; _onShortcutToggleChat: () => void;
@ -764,21 +762,6 @@ class Toolbox extends Component<Props, State> {
this._doToggleFullScreen(); this._doToggleFullScreen();
} }
_onToolbarToggleOverflowMenu: () => void;
/**
* Callback invoked to change whether the {@code OverflowMenu} is displayed
* or not.
*
* @private
* @returns {void}
*/
_onToolbarToggleOverflowMenu() {
sendAnalytics(createToolbarEvent('overflow'));
this.setState({ showOverflowMenu: !this.state.showOverflowMenu });
}
_onToolbarToggleProfile: () => void; _onToolbarToggleProfile: () => void;
/** /**
@ -1076,6 +1059,7 @@ function _mapStateToProps(state) {
const { const {
alwaysVisible, alwaysVisible,
fullScreen, fullScreen,
overflowMenuVisible,
timeoutID, timeoutID,
visible visible
} = state['features/toolbox']; } = state['features/toolbox'];
@ -1100,6 +1084,7 @@ function _mapStateToProps(state) {
_isRecording: isRecording, _isRecording: isRecording,
_fullScreen: fullScreen, _fullScreen: fullScreen,
_localParticipantID: localParticipant.id, _localParticipantID: localParticipant.id,
_overflowMenuVisible: overflowMenuVisible,
_raisedHand: localParticipant.raisedHand, _raisedHand: localParticipant.raisedHand,
_recordingEnabled: isModerator && enableRecording _recordingEnabled: isModerator && enableRecording
&& (conference && conference.isRecordingSupported()), && (conference && conference.isRecordingSupported()),

View File

@ -5,6 +5,7 @@ import { ReducerRegistry } from '../base/redux';
import { import {
CLEAR_TOOLBOX_TIMEOUT, CLEAR_TOOLBOX_TIMEOUT,
FULL_SCREEN_CHANGED, FULL_SCREEN_CHANGED,
SET_OVERFLOW_MENU_VISIBLE,
SET_TOOLBAR_HOVERED, SET_TOOLBAR_HOVERED,
SET_TOOLBOX_ALWAYS_VISIBLE, SET_TOOLBOX_ALWAYS_VISIBLE,
SET_TOOLBOX_ENABLED, SET_TOOLBOX_ENABLED,
@ -23,6 +24,7 @@ declare var interfaceConfig: Object;
* alwaysVisible: boolean, * alwaysVisible: boolean,
* enabled: boolean, * enabled: boolean,
* hovered: boolean, * hovered: boolean,
* overflowMenuVisible: boolean,
* timeoutID: number, * timeoutID: number,
* timeoutMS: number, * timeoutMS: number,
* visible: boolean * visible: boolean
@ -62,6 +64,13 @@ function _getInitialState() {
*/ */
hovered: false, hovered: false,
/**
* The indicator which determines whether the OverflowMenu is visible.
*
* @type {boolean}
*/
overflowMenuVisible: false,
/** /**
* A number, non-zero value which identifies the timer created by a call * A number, non-zero value which identifies the timer created by a call
* to setTimeout() with timeoutMS. * to setTimeout() with timeoutMS.
@ -103,6 +112,12 @@ ReducerRegistry.register(
fullScreen: action.fullScreen fullScreen: action.fullScreen
}; };
case SET_OVERFLOW_MENU_VISIBLE:
return {
...state,
overflowMenuVisible: action.visible
};
case SET_TOOLBAR_HOVERED: case SET_TOOLBAR_HOVERED:
return { return {
...state, ...state,