invite: remove duplicated code

Add ability to invite users which will use the share sheet or dialog
dynamically.
This commit is contained in:
Saúl Ibarra Corretgé 2020-03-24 13:37:24 +01:00 committed by Saúl Ibarra Corretgé
parent a7f8bf2d8f
commit cdc14586de
7 changed files with 39 additions and 54 deletions

View File

@ -4,13 +4,11 @@ import React, { PureComponent } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import { ColorSchemeRegistry } from '../../../base/color-scheme';
import { getFeatureFlag, INVITE_ENABLED } from '../../../base/flags';
import { connect } from '../../../base/redux';
import { StyleType } from '../../../base/styles';
import { translate } from '../../../base/i18n';
import { getParticipantCount } from '../../../base/participants';
import { isAddPeopleEnabled, isDialOutEnabled, setAddPeopleDialogVisible } from '../../../invite';
import { beginShareRoom } from '../../../share-room';
import { doInvitePeople } from '../../../invite/actions.native';
import styles from './styles';
import { Icon, IconAddPeople } from '../../../base/icons';
@ -20,11 +18,6 @@ import { Icon, IconAddPeople } from '../../../base/icons';
*/
type Props = {
/**
* True if any of the invite functions are enabled.
*/
_inviteEnabled: boolean,
/**
* True if it's a lonely meeting (participant count excluding fakes is 1).
*/
@ -112,13 +105,7 @@ class LonelyMeetingExperience extends PureComponent<Props> {
* @returns {void}
*/
_onPress() {
const { _inviteEnabled, dispatch } = this.props;
if (_inviteEnabled) {
dispatch(setAddPeopleDialogVisible(true));
} else {
dispatch(beginShareRoom());
}
this.props.dispatch(doInvitePeople());
}
}
@ -130,11 +117,7 @@ class LonelyMeetingExperience extends PureComponent<Props> {
* @returns {Props}
*/
function _mapStateToProps(state): $Shape<Props> {
const _inviteEnabled = getFeatureFlag(state, INVITE_ENABLED, true)
&& (isAddPeopleEnabled(state) || isDialOutEnabled(state));
return {
_inviteEnabled,
_isLonelyMeeting: getParticipantCount(state) === 1,
_styles: ColorSchemeRegistry.get(state, 'Conference')
};

View File

@ -0,0 +1,31 @@
// @flow
import type { Dispatch } from 'redux';
import { getFeatureFlag, INVITE_ENABLED } from '../base/flags';
import { beginShareRoom } from '../share-room';
import { setAddPeopleDialogVisible } from './actions.any';
import { isAddPeopleEnabled, isDialOutEnabled } from './functions';
export * from './actions.any';
/**
* Starts the process for inviting people. Dpending on the sysstem config it
* may use the system share sheet or the invite peoplee dialog.
*
* @returns {Function}
*/
export function doInvitePeople() {
return (dispatch: Dispatch<any>, getState: Function) => {
const state = getState();
const addPeopleEnabled = getFeatureFlag(state, INVITE_ENABLED, true)
&& (isAddPeopleEnabled(state) || isDialOutEnabled(state));
if (addPeopleEnabled) {
return dispatch(setAddPeopleDialogVisible(true));
}
return dispatch(beginShareRoom());
};
}

View File

@ -0,0 +1 @@
export * from './actions.any';

View File

@ -24,7 +24,7 @@ import {
} from '../../../../base/react';
import { connect } from '../../../../base/redux';
import { setAddPeopleDialogVisible } from '../../../actions';
import { setAddPeopleDialogVisible } from '../../../actions.native';
import AbstractAddPeopleDialog, {
type Props as AbstractProps,

View File

@ -2,24 +2,16 @@
import type { Dispatch } from 'redux';
import { getFeatureFlag, INVITE_ENABLED } from '../../../../base/flags';
import { translate } from '../../../../base/i18n';
import { IconAddPeople } from '../../../../base/icons';
import { connect } from '../../../../base/redux';
import { AbstractButton } from '../../../../base/toolbox';
import type { AbstractButtonProps } from '../../../../base/toolbox';
import { beginShareRoom } from '../../../../share-room';
import { setAddPeopleDialogVisible } from '../../../actions';
import { isAddPeopleEnabled, isDialOutEnabled } from '../../../functions';
import { doInvitePeople } from '../../../actions.native';
type Props = AbstractButtonProps & {
/**
* Whether the (backend) add people feature is enabled or not.
*/
_addPeopleEnabled: boolean,
/**
* The Redux dispatch function.
*/
@ -42,31 +34,9 @@ class InviteButton extends AbstractButton<Props, *> {
* @returns {void}
*/
_handleClick() {
const { _addPeopleEnabled, dispatch } = this.props;
if (_addPeopleEnabled) {
dispatch(setAddPeopleDialogVisible(true));
} else {
dispatch(beginShareRoom());
}
this.props.dispatch(doInvitePeople());
}
}
/**
* Maps (parts of) the redux state to {@link InviteButton}'s React {@code Component}
* props.
*
* @param {Object} state - The redux store/state.
* @private
* @returns {Object}
*/
function _mapStateToProps(state: Object) {
const addPeopleEnabled = getFeatureFlag(state, INVITE_ENABLED, true)
&& (isAddPeopleEnabled(state) || isDialOutEnabled(state));
return {
_addPeopleEnabled: addPeopleEnabled
};
}
export default translate(connect(_mapStateToProps)(InviteButton));
export default translate(connect()(InviteButton));

View File

@ -6,8 +6,8 @@ import Collapsible from 'react-native-collapsible';
import { ColorSchemeRegistry } from '../../../base/color-scheme';
import { BottomSheet, hideDialog, isDialogOpen } from '../../../base/dialog';
import { IconDragHandle } from '../../../base/icons';
import { IOS_RECORDING_ENABLED, getFeatureFlag } from '../../../base/flags';
import { IconDragHandle } from '../../../base/icons';
import { connect } from '../../../base/redux';
import { StyleType } from '../../../base/styles';
import { SharedDocumentButton } from '../../../etherpad';