2018-08-08 18:48:23 +00:00
|
|
|
// @flow
|
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2018-08-08 18:48:23 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
createToolbarEvent,
|
|
|
|
sendAnalytics
|
|
|
|
} from '../../analytics';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { TILE_VIEW_ENABLED, getFeatureFlag } from '../../base/flags';
|
2018-08-08 18:48:23 +00:00
|
|
|
import { translate } from '../../base/i18n';
|
2019-08-30 16:39:06 +00:00
|
|
|
import { IconTileView } from '../../base/icons';
|
2020-07-23 13:12:25 +00:00
|
|
|
import { getParticipantCount } from '../../base/participants';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../base/redux';
|
2020-07-24 12:14:33 +00:00
|
|
|
import { AbstractButton, type AbstractButtonProps } from '../../base/toolbox/components';
|
2018-08-08 18:48:23 +00:00
|
|
|
import { setTileView } from '../actions';
|
2020-07-23 13:12:25 +00:00
|
|
|
import { shouldDisplayTileView } from '../functions';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from '../logger';
|
2019-08-08 15:28:21 +00:00
|
|
|
|
2018-08-08 18:48:23 +00:00
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link TileViewButton}.
|
|
|
|
*/
|
|
|
|
type Props = AbstractButtonProps & {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not tile view layout has been enabled as the user preference.
|
|
|
|
*/
|
|
|
|
_tileViewEnabled: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to dispatch actions from the buttons.
|
|
|
|
*/
|
2019-03-19 15:42:25 +00:00
|
|
|
dispatch: Dispatch<any>
|
2018-08-08 18:48:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that renders a toolbar button for toggling the tile layout view.
|
|
|
|
*
|
|
|
|
* @extends AbstractButton
|
|
|
|
*/
|
|
|
|
class TileViewButton<P: Props> extends AbstractButton<P, *> {
|
|
|
|
accessibilityLabel = 'toolbar.accessibilityLabel.tileView';
|
2019-08-30 16:39:06 +00:00
|
|
|
icon = IconTileView;
|
2019-03-05 14:26:45 +00:00
|
|
|
label = 'toolbar.enterTileView';
|
|
|
|
toggledLabel = 'toolbar.exitTileView';
|
2018-08-08 18:48:23 +00:00
|
|
|
tooltip = 'toolbar.tileViewToggle';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles clicking / pressing the button.
|
|
|
|
*
|
|
|
|
* @override
|
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_handleClick() {
|
|
|
|
const { _tileViewEnabled, dispatch } = this.props;
|
|
|
|
|
|
|
|
sendAnalytics(createToolbarEvent(
|
|
|
|
'tileview.button',
|
|
|
|
{
|
|
|
|
'is_enabled': _tileViewEnabled
|
|
|
|
}));
|
2019-08-08 15:28:21 +00:00
|
|
|
const value = !_tileViewEnabled;
|
2018-08-08 18:48:23 +00:00
|
|
|
|
2019-08-08 15:28:21 +00:00
|
|
|
logger.debug(`Tile view ${value ? 'enable' : 'disable'}`);
|
|
|
|
dispatch(setTileView(value));
|
2018-08-08 18:48:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether this button is in toggled state or not.
|
|
|
|
*
|
|
|
|
* @override
|
|
|
|
* @protected
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_isToggled() {
|
|
|
|
return this.props._tileViewEnabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the associated props for the
|
|
|
|
* {@code TileViewButton} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
2020-05-06 12:22:59 +00:00
|
|
|
* @param {Object} ownProps - The properties explicitly passed to the component instance.
|
|
|
|
* @returns {Props}
|
2018-08-08 18:48:23 +00:00
|
|
|
*/
|
2020-05-06 12:22:59 +00:00
|
|
|
function _mapStateToProps(state, ownProps) {
|
|
|
|
const enabled = getFeatureFlag(state, TILE_VIEW_ENABLED, true);
|
2020-07-23 13:12:25 +00:00
|
|
|
const lonelyMeeting = getParticipantCount(state) < 2;
|
|
|
|
const { visible = enabled && !lonelyMeeting } = ownProps;
|
2020-05-06 12:22:59 +00:00
|
|
|
|
2018-08-08 18:48:23 +00:00
|
|
|
return {
|
2020-07-23 13:12:25 +00:00
|
|
|
_tileViewEnabled: shouldDisplayTileView(state),
|
2020-05-06 12:22:59 +00:00
|
|
|
visible
|
2018-08-08 18:48:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(TileViewButton));
|