import classNames from 'classnames'; import PropTypes from 'prop-types'; import React from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { FormattedMessage, injectIntl, defineMessages } from 'react-intl'; import { connect } from 'react-redux'; import { Link, NavLink, withRouter } from 'react-router-dom'; import { getSettings } from 'soapbox/actions/settings'; import { getSoapboxConfig } from 'soapbox/actions/soapbox'; import Icon from 'soapbox/components/icon'; import IconWithCounter from 'soapbox/components/icon_with_counter'; import SearchContainer from 'soapbox/features/compose/containers/search_container'; import { isStaff } from 'soapbox/utils/accounts'; import { getFeatures } from 'soapbox/utils/features'; import { openModal } from '../../../actions/modals'; import { openSidebar } from '../../../actions/sidebar'; import Avatar from '../../../components/avatar'; import ThemeToggle from '../../ui/components/theme_toggle_container'; import ProfileDropdown from './profile_dropdown'; 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, features: PropTypes.object.isRequired, dashboardCount: PropTypes.number, notificationCount: PropTypes.number, chatsCount: PropTypes.number, singleUserMode: PropTypes.bool, } state = { collapsed: false, } static contextTypes = { router: PropTypes.object, } setRef = ref => { this.node = ref; } isHomeActive = (match, location) => { const { pathname } = location; return pathname === '/' || pathname.startsWith('/timeline/'); } shouldShowLinks = () => { try { const { pathname } = this.context.router.route.location; return (pathname.startsWith('/@') && !pathname.includes('/posts/')) || pathname.startsWith('/admin'); } catch { return false; } } render() { const { intl, account, logo, onOpenCompose, onOpenSidebar, features, dashboardCount, notificationCount, chatsCount, singleUserMode } = this.props; const { collapsed } = this.state; const showLinks = this.shouldShowLinks(); 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(); const instance = state.get('instance'); const settings = getSettings(state); const soapboxConfig = getSoapboxConfig(state); // In demo mode, use the Soapbox logo const logo = settings.get('demo') ? require('images/soapbox-logo.svg') : getSoapboxConfig(state).get('logo'); return { account: state.getIn(['accounts', me]), logo, features: getFeatures(instance), notificationCount: state.getIn(['notifications', 'unread']), chatsCount: state.getIn(['chats', 'items']).reduce((acc, curr) => acc + Math.min(curr.get('unread', 0), 1), 0), dashboardCount: reportsCount + approvalCount, singleUserMode: soapboxConfig.get('singleUserMode'), }; }; const mapDispatchToProps = (dispatch) => ({ onOpenCompose() { dispatch(openModal('COMPOSE')); }, onOpenSidebar() { dispatch(openSidebar()); }, }); export default withRouter(injectIntl( connect(mapStateToProps, mapDispatchToProps, null, { forwardRef: true }, )(TabsBar)));