about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/ui/components/notifications_counter_icon.js
blob: 25df35264d07817ae5e51a42e590bd88a143f2f2 (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
25
26
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, className, showBadge }) => (
  <i className='icon-with-badge'>
    <Icon icon='bell' fixedWidth className={className} />
    {showBadge && count > 0 && <i className='icon-with-badge__badge'>{formatNumber(count)}</i>}
  </i>
);

NotificationsCounterIcon.propTypes = {
  count: PropTypes.number.isRequired,
  showBadge: PropTypes.bool,
  className: PropTypes.string,
};

export default connect(mapStateToProps)(NotificationsCounterIcon);