Files
jitsi-meet/react/features/presence-status/components/PresenceLabel.js
Leonard Kim 486e8e35d9 ref: move all prop type declaration to flow
For the most part the changes are taking the "static propTypes" declaration off
of components and declaring them as Flow types. Sometimes to support flow some
method signatures had to be added. There are some exceptions in which more had
to be done to tame the beast:
- AbstractVideoTrack: put in additional truthy checks for videoTrack.
- Video: add truthy checks for the _videoElement ref.
- shouldRenderVideoTrack function: Some component could pass null for the
  videoTrack argument and Flow wanted that called out explicitly.
- DisplayName: Add a truthy check for the input ref before acting on it.
- NumbersList: Move array checks inline for Flow to comprehend array methods
  could be called. Add type checks in the Object.entries loop as the value is
  assumed to be a mixed type by Flow.
- AbstractToolbarButton: add additional truthy check for passed in type.
2018-11-07 17:38:10 +01:00

133 lines
2.8 KiB
JavaScript

/* @flow */
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { translate } from '../../base/i18n';
import { getParticipantById } from '../../base/participants';
import { Text } from '../../base/react';
import { STATUS_TO_I18N_KEY } from '../constants';
/**
* The type of the React {@code Component} props of {@link PresenceLabel}.
*/
type Props = {
/**
* The current present status associated with the passed in participantID
* prop.
*/
_presence: string,
/**
* Class name for the presence label.
*/
className: string,
/**
* Default presence status that will be displayed if user's presence status
* is not available.
*/
defaultPresence: string,
/**
* The ID of the participant whose presence status should display.
*/
participantID: string,
/**
* Styles for the presence label.
*/
style: Object,
/**
* Invoked to obtain translated strings.
*/
t: Function
};
/**
* React {@code Component} for displaying the current presence status of a
* participant.
*
* @extends Component
*/
class PresenceLabel extends Component<Props> {
/**
* The default values for {@code PresenceLabel} component's property types.
*
* @static
*/
static defaultProps = {
_presence: ''
};
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
const text = this._getPresenceText();
if (text === null) {
return null;
}
const { style, className } = this.props;
return (
<Text
className = { className }
{ ...style }>
{ text }
</Text>);
}
/**
* Returns the text associated with the current presence status.
*
* @returns {string}
*/
_getPresenceText() {
const { _presence, t } = this.props;
if (!_presence) {
return null;
}
const i18nKey = STATUS_TO_I18N_KEY[_presence];
if (!i18nKey) { // fallback to status value
return _presence;
}
return t(i18nKey);
}
}
/**
* Maps (parts of) the Redux state to the associated {@code PresenceLabel}'s
* props.
*
* @param {Object} state - The Redux state.
* @param {Object} ownProps - The React Component props passed to the associated
* instance of {@code PresenceLabel}.
* @private
* @returns {{
* _presence: (string|undefined)
* }}
*/
function _mapStateToProps(state, ownProps) {
const participant = getParticipantById(state, ownProps.participantID);
return {
_presence:
(participant && participant.presence) || ownProps.defaultPresence
};
}
export default translate(connect(_mapStateToProps)(PresenceLabel));