about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/ui/components/notifications_counter_icon.js
blob: 137658b94cc9c8fef6753f8c9ea75842adcf17ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import Icon from 'flavours/glitch/components/icon';

const mapStateToProps = state => ({
  count: state.getIn(['notifications', 'unread']),
  showBadge: state.getIn(['local_settings', 'notifications', 'tab_badge']),
});

const formatNumber = num => num > 99 ? '99+' : num;

const NotificationsCounterIcon = ({ count, showBadge }) => (
  <i className='icon-with-badge'>
    <Icon icon='bell' fixedWidth />
    {showBadge && count > 0 && <i className='icon-with-badge__badge'>{formatNumber(count)}</i>}
  </i>
);

NotificationsCounterIcon.propTypes = {
  count: PropTypes.number.isRequired,
};

export default connect(mapStateToProps)(NotificationsCounterIcon);