From 03344756e552b16c29790560135acd9aebde3bea Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 29 Dec 2020 19:48:39 -0600 Subject: [PATCH] Admin: display awaiting-approval counter in nav --- app/soapbox/components/icon_with_counter.js | 23 ++++++++++++++++ .../features/admin/components/admin_nav.js | 12 ++++++--- app/styles/components/promo-panel.scss | 3 ++- app/styles/ui.scss | 26 +++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 app/soapbox/components/icon_with_counter.js diff --git a/app/soapbox/components/icon_with_counter.js b/app/soapbox/components/icon_with_counter.js new file mode 100644 index 000000000..0daf608da --- /dev/null +++ b/app/soapbox/components/icon_with_counter.js @@ -0,0 +1,23 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import Icon from 'soapbox/components/icon'; +import { shortNumberFormat } from 'soapbox/utils/numbers'; + +const IconWithCounter = ({ icon, count, fixedWidth }) => { + return ( +
+ + {count > 0 && + {shortNumberFormat(count)} + } +
+ ); +}; + +IconWithCounter.propTypes = { + icon: PropTypes.string.isRequired, + count: PropTypes.number.isRequired, + fixedWidth: PropTypes.bool, +}; + +export default IconWithCounter; diff --git a/app/soapbox/features/admin/components/admin_nav.js b/app/soapbox/features/admin/components/admin_nav.js index 12a53b3fd..47076abf8 100644 --- a/app/soapbox/features/admin/components/admin_nav.js +++ b/app/soapbox/features/admin/components/admin_nav.js @@ -1,12 +1,16 @@ import React from 'react'; import { connect } from 'react-redux'; +import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import Icon from 'soapbox/components/icon'; +import IconWithCounter from 'soapbox/components/icon_with_counter'; import { NavLink } from 'react-router-dom'; import { FormattedMessage } from 'react-intl'; const mapStateToProps = (state, props) => ({ instance: state.get('instance'), + approvalCount: state.getIn(['admin', 'awaitingApproval']).count(), + reportsCount: state.getIn(['admin', 'open_report_count']), }); export default @connect(mapStateToProps) @@ -14,10 +18,12 @@ class AdminNav extends React.PureComponent { static propTypes = { instance: ImmutablePropTypes.map.isRequired, + approvalCount: PropTypes.number, + reportsCount: PropTypes.number, }; render() { - const { instance } = this.props; + const { instance, approvalCount, reportsCount } = this.props; return ( <> @@ -28,12 +34,12 @@ class AdminNav extends React.PureComponent { - + {instance.get('approval_required') && ( - + )} diff --git a/app/styles/components/promo-panel.scss b/app/styles/components/promo-panel.scss index e2030cee6..78625e338 100644 --- a/app/styles/components/promo-panel.scss +++ b/app/styles/components/promo-panel.scss @@ -28,7 +28,8 @@ } } - &__icon { + &__icon, + .icon-with-counter { margin-right: 12px; } } diff --git a/app/styles/ui.scss b/app/styles/ui.scss index a2ca21a06..0b4fa30d3 100644 --- a/app/styles/ui.scss +++ b/app/styles/ui.scss @@ -699,3 +699,29 @@ text-align: center; } } + +.icon-with-counter { + position: relative; + display: inline; + + &__counter { + @include font-montserrat; + @include font-size(14); + @include line-height(14); + position: absolute; + box-sizing: border-box; + left: 8px; + top: -12px; + min-width: 16px; + height: 16px; + padding: 1px 3px 0; + border-radius: 8px; + text-align: center; + color: #fff; + background: var(--accent-color); + + @media screen and (max-width: 895px) { + top: 0; + } + } +}