2019-05-23 08:35:22 +09: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-26 04:27:00 +09:00
|
|
|
const NotificationsCounterIcon = ({ count, className }) => (
|
2019-05-23 08:35:22 +09:00
|
|
|
<i className='icon-with-badge'>
|
2019-05-26 04:27:00 +09:00
|
|
|
<Icon id='bell' fixedWidth className={className} />
|
2019-05-23 08:35:22 +09:00
|
|
|
{count > 0 && <i className='icon-with-badge__badge'>{formatNumber(count)}</i>}
|
|
|
|
</i>
|
|
|
|
);
|
|
|
|
|
|
|
|
NotificationsCounterIcon.propTypes = {
|
|
|
|
count: PropTypes.number.isRequired,
|
2019-05-26 04:27:00 +09:00
|
|
|
className: PropTypes.string,
|
2019-05-23 08:35:22 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(NotificationsCounterIcon);
|