bigbuffet-rw/app/soapbox/components/primary_navigation.js

173 lines
7.1 KiB
JavaScript
Raw Normal View History

2021-09-12 16:16:53 -07:00
'use strict';
import classNames from 'classnames';
2021-09-12 16:16:53 -07:00
import PropTypes from 'prop-types';
import React from 'react';
2021-09-12 16:16:53 -07:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
2021-09-12 16:16:53 -07:00
import { NavLink, withRouter } from 'react-router-dom';
import { getSettings } from 'soapbox/actions/settings';
2021-09-12 16:16:53 -07:00
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
import Icon from 'soapbox/components/icon';
import IconWithCounter from 'soapbox/components/icon_with_counter';
import { isStaff, getBaseURL } from 'soapbox/utils/accounts';
import { getFeatures } from 'soapbox/utils/features';
2021-09-12 16:16:53 -07:00
const mapStateToProps = state => {
const me = state.get('me');
const account = state.getIn(['accounts', me]);
2021-09-12 16:16:53 -07:00
const reportsCount = state.getIn(['admin', 'openReports']).count();
const approvalCount = state.getIn(['admin', 'awaitingApproval']).count();
const instance = state.get('instance');
return {
account,
2021-09-12 16:16:53 -07:00
logo: getSoapboxConfig(state).get('logo'),
notificationCount: state.getIn(['notifications', 'unread']),
chatsCount: state.getIn(['chats', 'items']).reduce((acc, curr) => acc + Math.min(curr.get('unread', 0), 1), 0),
2021-09-12 16:16:53 -07:00
dashboardCount: reportsCount + approvalCount,
baseURL: getBaseURL(account),
settings: getSettings(state),
2021-09-12 16:16:53 -07:00
features: getFeatures(instance),
instance,
2021-09-12 16:16:53 -07:00
};
};
export default @withRouter @connect(mapStateToProps)
class PrimaryNavigation extends React.PureComponent {
static contextTypes = {
router: PropTypes.object,
};
static propTypes = {
dispatch: PropTypes.func.isRequired,
logo: PropTypes.string,
account: ImmutablePropTypes.map,
dashboardCount: PropTypes.number,
notificationCount: PropTypes.number,
chatsCount: PropTypes.number,
baseURL: PropTypes.string,
settings: PropTypes.object.isRequired,
2021-09-12 16:16:53 -07:00
features: PropTypes.object.isRequired,
2021-09-20 19:13:22 -07:00
location: PropTypes.object,
instance: ImmutablePropTypes.map.isRequired,
2021-09-12 16:16:53 -07:00
};
render() {
const { account, settings, features, notificationCount, chatsCount, dashboardCount, location, instance, baseURL } = this.props;
2021-09-12 16:16:53 -07:00
return (
<div className='column-header__wrapper primary-navigation__wrapper'>
<h1 className='column-header primary-navigation'>
<NavLink to='/' exact className='btn grouped'>
2021-10-05 15:58:25 -07:00
<Icon
src={require('icons/home-square.svg')}
className={classNames('primary-navigation__icon', 'svg-icon--home', { 'svg-icon--active': location.pathname === '/' })}
/>
2021-09-12 16:16:53 -07:00
<FormattedMessage id='tabs_bar.home' defaultMessage='Home' />
</NavLink>
<NavLink key='search' className='btn grouped' to='/search'>
<Icon
src={require('@tabler/icons/icons/search.svg')}
className={classNames('primary-navigation__icon', { 'svg-icon--active': location.pathname === '/search' })}
/>
<FormattedMessage id='navigation.search' defaultMessage='Search' />
</NavLink>
{account && (
<NavLink key='notifications' className='btn grouped' to='/notifications' data-preview-title-id='column.notifications'>
<IconWithCounter
src={require('@tabler/icons/icons/bell.svg')}
className={classNames('primary-navigation__icon', {
'svg-icon--active': location.pathname === '/notifications',
'svg-icon--unread': notificationCount > 0,
})}
count={notificationCount}
/>
<FormattedMessage id='tabs_bar.notifications' defaultMessage='Notifications' />
</NavLink>
)}
{account && (
features.chats ? (
<NavLink key='chats' className='btn grouped' to='/chats' data-preview-title-id='column.chats'>
<IconWithCounter
src={require('@tabler/icons/icons/messages.svg')}
className={classNames('primary-navigation__icon', { 'svg-icon--active': location.pathname === '/chats' })}
count={chatsCount}
/>
<FormattedMessage id='tabs_bar.chats' defaultMessage='Chats' />
</NavLink>
) : (
<NavLink to='/messages' className='btn grouped'>
<Icon
src={require('@tabler/icons/icons/mail.svg')}
className={classNames('primary-navigation__icon', { 'svg-icon--active': ['/messages', '/conversations'].includes(location.pathname) })}
/>
<FormattedMessage id='navigation.direct_messages' defaultMessage='Messages' />
</NavLink>
)
)}
2021-09-12 16:16:53 -07:00
{(account && isStaff(account)) && (
<NavLink key='dashboard' className='btn grouped' to='/admin' data-preview-title-id='tabs_bar.dashboard'>
<IconWithCounter
src={location.pathname.startsWith('/admin') ? require('icons/dashboard-filled.svg') : require('@tabler/icons/icons/dashboard.svg')}
className='primary-navigation__icon'
count={dashboardCount}
/>
<FormattedMessage id='tabs_bar.dashboard' defaultMessage='Dashboard' />
</NavLink>
)}
{(account && instance.get('invites_enabled')) && (
<a href={`${baseURL}/invites`} className='btn grouped'>
<Icon src={require('@tabler/icons/icons/mailbox.svg')} className='primary-navigation__icon' />
<FormattedMessage id='navigation.invites' defaultMessage='Invites' />
</a>
)}
2021-09-12 16:16:53 -07:00
{(settings.get('isDeveloper')) && (
<NavLink key='developers' className='btn grouped' to='/developers'>
<Icon
src={require('@tabler/icons/icons/code.svg')}
className={classNames('primary-navigation__icon', { 'svg-icon--active': location.pathname.startsWith('/developers') })}
/>
<FormattedMessage id='navigation.developers' defaultMessage='Developers' />
</NavLink>
)}
<hr />
2021-09-12 16:16:53 -07:00
{features.federating ? (
<NavLink to='/timeline/local' className='btn grouped'>
2021-09-20 19:13:22 -07:00
<Icon
src={require('@tabler/icons/icons/users.svg')}
className={classNames('primary-navigation__icon', { 'svg-icon--active': location.pathname === '/timeline/local' })}
/>
{instance.get('title')}
</NavLink>
) : (
<NavLink to='/timeline/local' className='btn grouped'>
<Icon src={require('@tabler/icons/icons/world.svg')} className='primary-navigation__icon' />
<FormattedMessage id='tabs_bar.all' defaultMessage='All' />
</NavLink>
)}
{features.federating && (
<NavLink to='/timeline/fediverse' className='btn grouped'>
<Icon src={require('icons/fediverse.svg')} className='column-header__icon' />
<FormattedMessage id='tabs_bar.fediverse' defaultMessage='Fediverse' />
</NavLink>
)}
2021-09-12 16:16:53 -07:00
</h1>
</div>
);
}
}