jiti-meet/react/features/conference/components/native/LonelyMeetingExperience.tsx

154 lines
4.5 KiB
TypeScript
Raw Normal View History

/* eslint-disable lines-around-comment */
2020-03-20 17:30:46 +00:00
import React, { PureComponent } from 'react';
import { WithTranslation } from 'react-i18next';
import { Text, View } from 'react-native';
2020-03-20 17:30:46 +00:00
import { IReduxState } from '../../../app/types';
// @ts-ignore
import { INVITE_ENABLED, getFeatureFlag } from '../../../base/flags/';
import { translate } from '../../../base/i18n/functions';
// @ts-ignore
import { Icon, IconAddUser } from '../../../base/icons';
import { getParticipantCountWithFake } from '../../../base/participants/functions';
import { connect } from '../../../base/redux/functions';
import Button from '../../../base/ui/components/native/Button';
import { BUTTON_TYPES } from '../../../base/ui/constants.native';
import { isInBreakoutRoom } from '../../../breakout-rooms/functions';
import { doInvitePeople } from '../../../invite/actions.native';
import { toggleShareDialog } from '../../../share-room/actions';
import { getInviteOthersControl } from '../../../share-room/functions';
2020-03-20 17:30:46 +00:00
// @ts-ignore
2020-03-20 17:30:46 +00:00
import styles from './styles';
2020-03-20 17:30:46 +00:00
/**
* Props type of the component.
*/
type Props = WithTranslation & {
2020-03-20 17:30:46 +00:00
/**
* Control for invite other button.
*/
_inviteOthersControl: any;
/**
* True if currently in a breakout room.
*/
_isInBreakoutRoom: boolean;
/**
* True if the invite functions (dial out, invite, share...etc) are disabled.
*/
_isInviteFunctionsDisabled: boolean;
2020-03-20 17:30:46 +00:00
/**
* True if it's a lonely meeting (participant count excluding fakes is 1).
*/
_isLonelyMeeting: boolean;
2020-03-20 17:30:46 +00:00
/**
* The Redux Dispatch function.
*/
dispatch: Function;
2020-03-20 17:30:46 +00:00
/**
* Function to be used to translate i18n labels.
*/
t: Function;
2020-03-20 17:30:46 +00:00
};
/**
* Implements the UI elements to be displayed in the lonely meeting experience.
*/
class LonelyMeetingExperience extends PureComponent<Props> {
/**
* Instantiates a new component.
*
* @inheritdoc
*/
constructor(props: Props) {
super(props);
this._onPress = this._onPress.bind(this);
}
/**
* Implements {@code PureComponent#render}.
*
* @inheritdoc
*/
render() {
const {
_inviteOthersControl,
_isInBreakoutRoom,
_isInviteFunctionsDisabled,
_isLonelyMeeting,
t
} = this.props;
const { color, shareDialogVisible } = _inviteOthersControl;
2020-03-20 17:30:46 +00:00
if (!_isLonelyMeeting) {
return null;
}
return (
<View style = { styles.lonelyMeetingContainer }>
2022-06-20 21:09:13 +00:00
<Text style = { styles.lonelyMessage }>
2020-03-20 17:30:46 +00:00
{ t('lonelyMeetingExperience.youAreAlone') }
</Text>
{ !_isInviteFunctionsDisabled && !_isInBreakoutRoom && (
<Button
accessibilityLabel = 'lonelyMeetingExperience.button'
disabled = { shareDialogVisible }
// eslint-disable-next-line react/jsx-no-bind
icon = { () => (
<Icon
color = { color }
size = { 20 }
src = { IconAddUser } />
) }
labelKey = 'lonelyMeetingExperience.button'
onClick = { this._onPress }
type = { BUTTON_TYPES.PRIMARY } />
) }
2020-03-20 17:30:46 +00:00
</View>
);
}
/**
* Callback for the onPress function of the button.
*
* @returns {void}
*/
_onPress() {
this.props.dispatch(toggleShareDialog(true));
this.props.dispatch(doInvitePeople());
2020-03-20 17:30:46 +00:00
}
}
/**
* Maps parts of the Redux state to the props of this Component.
*
* @param {Object} state - The redux state.
* @private
* @returns {Props}
*/
function _mapStateToProps(state: IReduxState) {
const { disableInviteFunctions } = state['features/base/config'];
const { conference } = state['features/base/conference'];
const _inviteOthersControl = getInviteOthersControl(state);
const flag = getFeatureFlag(state, INVITE_ENABLED, true);
const _isInBreakoutRoom = isInBreakoutRoom(state);
2020-03-20 17:30:46 +00:00
return {
_inviteOthersControl,
_isInBreakoutRoom,
_isInviteFunctionsDisabled: !flag || disableInviteFunctions,
_isLonelyMeeting: conference && getParticipantCountWithFake(state) === 1
2020-03-20 17:30:46 +00:00
};
}
export default connect(_mapStateToProps)(translate(LonelyMeetingExperience));