jiti-meet/react/features/chat/components/native/ChatButton.js

71 lines
1.7 KiB
JavaScript
Raw Normal View History

// @flow
import { CHAT_ENABLED, getFeatureFlag } from '../../../base/flags';
2019-08-30 16:39:06 +00:00
import { IconChat, IconChatUnread } from '../../../base/icons';
2019-03-21 16:38:29 +00:00
import { connect } from '../../../base/redux';
import {
AbstractButton,
type AbstractButtonProps
2020-07-24 12:14:33 +00:00
} from '../../../base/toolbox/components';
import { openChat } from '../../actions.native';
import { getUnreadCount } from '../../functions';
type Props = AbstractButtonProps & {
/**
* The unread message count.
*/
_unreadMessageCount: number,
dispatch: Function
};
/**
* Implements an {@link AbstractButton} to open the chat screen on mobile.
*/
class ChatButton extends AbstractButton<Props, *> {
accessibilityLabel = 'toolbar.accessibilityLabel.chat';
2019-08-30 16:39:06 +00:00
icon = IconChat;
label = 'toolbar.chat';
2019-08-30 16:39:06 +00:00
toggledIcon = IconChatUnread;
/**
* Handles clicking / pressing the button, and opens the appropriate dialog.
*
* @private
* @returns {void}
*/
_handleClick() {
this.props.dispatch(openChat());
}
/**
* Renders the button toggled when there are unread messages.
*
* @protected
* @returns {boolean}
*/
_isToggled() {
return Boolean(this.props._unreadMessageCount);
}
}
/**
* Maps part of the redux state to the component's props.
*
* @param {Object} state - The Redux state.
* @param {Object} ownProps - The properties explicitly passed to the component instance.
* @returns {Props}
*/
function _mapStateToProps(state, ownProps) {
const enabled = getFeatureFlag(state, CHAT_ENABLED, true);
const { visible = enabled } = ownProps;
return {
_unreadMessageCount: getUnreadCount(state),
visible
};
}
export default connect(_mapStateToProps)(ChatButton);