bigbuffet-rw/app/soapbox/components/more_follows.js

69 lines
1.6 KiB
JavaScript
Raw Normal View History

import PropTypes from 'prop-types';
import React from 'react';
2020-05-27 17:36:23 -07:00
import { defineMessages, injectIntl } from 'react-intl';
import { connect } from 'react-redux';
2021-10-06 08:58:29 -07:00
import { getFeatures } from 'soapbox/utils/features';
2020-05-27 17:36:23 -07:00
const messages = defineMessages({
2020-06-06 12:06:45 -07:00
following: {
id: 'morefollows.following_label',
defaultMessage: '…and {count} more {count, plural, one {follow} other {follows}} on remote sites.',
2020-05-27 17:36:23 -07:00
},
2020-06-06 12:06:45 -07:00
followers: {
id: 'morefollows.followers_label',
defaultMessage: '…and {count} more {count, plural, one {follower} other {followers}} on remote sites.',
2020-05-27 17:36:23 -07:00
},
});
2021-10-06 08:58:29 -07:00
const mapStateToProps = state => {
const instance = state.get('instance');
return {
features: getFeatures(instance),
};
};
export default @connect(mapStateToProps)
@injectIntl
2020-05-27 17:36:23 -07:00
class MoreFollows extends React.PureComponent {
static propTypes = {
visible: PropTypes.bool,
2020-05-27 17:36:23 -07:00
count: PropTypes.number,
type: PropTypes.string,
intl: PropTypes.object.isRequired,
2021-10-06 08:58:29 -07:00
features: PropTypes.object.isRequired,
}
static defaultProps = {
visible: true,
}
2020-05-27 17:36:23 -07:00
getMessage = () => {
const { type, count, intl } = this.props;
2020-06-06 12:06:45 -07:00
return intl.formatMessage(messages[type], { count });
2020-05-27 17:36:23 -07:00
}
2020-05-27 17:36:23 -07:00
render() {
2021-10-06 08:58:29 -07:00
const { features } = this.props;
// If the instance isn't federating, there are no remote followers
if (!features.federating) {
return null;
}
2020-05-27 17:36:23 -07:00
return (
<div className='morefollows-indicator'>
<div>
<div className='morefollows-indicator__label' style={{ visibility: this.props.visible ? 'visible' : 'hidden' }}>
{this.getMessage()}
</div>
</div>
2020-05-27 17:36:23 -07:00
</div>
);
}
}