import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { Link, NavLink, withRouter } from 'react-router-dom'; import { FormattedMessage, injectIntl, defineMessages } from 'react-intl'; import { connect } from 'react-redux'; import classNames from 'classnames'; import IconWithCounter from 'soapbox/components/icon_with_counter'; import SearchContainer from 'soapbox/features/compose/containers/search_container'; import Avatar from '../../../components/avatar'; import ProfileDropdown from './profile_dropdown'; import { openModal } from '../../../actions/modal'; import { openSidebar } from '../../../actions/sidebar'; import Icon from '../../../components/icon'; import ThemeToggle from '../../ui/components/theme_toggle_container'; import { getSoapboxConfig } from 'soapbox/actions/soapbox'; import { isStaff } from 'soapbox/utils/accounts'; const messages = defineMessages({ post: { id: 'tabs_bar.post', defaultMessage: 'Post' }, }); class TabsBar extends React.PureComponent { static propTypes = { intl: PropTypes.object.isRequired, history: PropTypes.object.isRequired, onOpenCompose: PropTypes.func, onOpenSidebar: PropTypes.func.isRequired, logo: PropTypes.string, account: ImmutablePropTypes.map, dashboardCount: PropTypes.number, notificationCount: PropTypes.number, chatsCount: PropTypes.number, } state = { collapsed: false, } static contextTypes = { router: PropTypes.object, } setRef = ref => { this.node = ref; } isHomeActive = (match, location) => { const { pathname } = location; return pathname === '/' || pathname.startsWith('/timeline/'); } getNavLinks() { const { intl: { formatMessage }, logo, account, dashboardCount, notificationCount, chatsCount } = this.props; let links = []; if (logo) { links.push( Logo ); } links.push( ); if (account) { links.push( ); } if (account) { links.push( ); } if (account && isStaff(account)) { links.push( ); } links.push( , ); return links.map((link) => React.cloneElement(link, { 'aria-label': formatMessage({ id: link.props['data-preview-title-id'], }), })); } render() { const { account, onOpenCompose, onOpenSidebar, intl } = this.props; const { collapsed } = this.state; const classes = classNames('tabs-bar', { 'tabs-bar--collapsed': collapsed, }); return ( ); } } const mapStateToProps = state => { const me = state.get('me'); const reportsCount = state.getIn(['admin', 'openReports']).count(); const approvalCount = state.getIn(['admin', 'awaitingApproval']).count(); return { account: state.getIn(['accounts', me]), logo: getSoapboxConfig(state).get('logo'), notificationCount: state.getIn(['notifications', 'unread']), chatsCount: state.get('chats').reduce((acc, curr) => acc + Math.min(curr.get('unread', 0), 1), 0), dashboardCount: reportsCount + approvalCount, }; }; const mapDispatchToProps = (dispatch) => ({ onOpenCompose() { dispatch(openModal('COMPOSE')); }, onOpenSidebar() { dispatch(openSidebar()); }, }); export default withRouter(injectIntl( connect(mapStateToProps, mapDispatchToProps, null, { forwardRef: true }, )(TabsBar)));