2019-05-23 01:35:22 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import Icon from 'mastodon/components/icon';
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
count: state.getIn(['notifications', 'unread']),
|
|
|
|
});
|
|
|
|
|
|
|
|
const formatNumber = num => num > 99 ? '99+' : num;
|
|
|
|
|
2019-05-25 21:27:00 +02:00
|
|
|
const NotificationsCounterIcon = ({ count, className }) => (
|
2019-05-23 01:35:22 +02:00
|
|
|
<i className='icon-with-badge'>
|
2019-05-25 21:27:00 +02:00
|
|
|
<Icon id='bell' fixedWidth className={className} />
|
2019-05-23 01:35:22 +02:00
|
|
|
{count > 0 && <i className='icon-with-badge__badge'>{formatNumber(count)}</i>}
|
|
|
|
</i>
|
|
|
|
);
|
|
|
|
|
|
|
|
NotificationsCounterIcon.propTypes = {
|
|
|
|
count: PropTypes.number.isRequired,
|
2019-05-25 21:27:00 +02:00
|
|
|
className: PropTypes.string,
|
2019-05-23 01:35:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(NotificationsCounterIcon);
|