2020-03-27 13:59:38 -07:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-04-14 14:37:17 -07:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2021-09-12 16:51:39 -07:00
|
|
|
import { Link, withRouter } from 'react-router-dom';
|
2020-06-06 12:57:05 -07:00
|
|
|
import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
|
2020-03-27 13:59:38 -07:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import classNames from 'classnames';
|
2020-05-28 15:52:07 -07:00
|
|
|
import SearchContainer from 'soapbox/features/compose/containers/search_container';
|
2020-03-27 13:59:38 -07:00
|
|
|
import Avatar from '../../../components/avatar';
|
2021-03-23 17:06:55 -07:00
|
|
|
import ProfileDropdown from './profile_dropdown';
|
2020-03-27 13:59:38 -07:00
|
|
|
import { openModal } from '../../../actions/modal';
|
|
|
|
import { openSidebar } from '../../../actions/sidebar';
|
2020-10-01 17:33:03 -07:00
|
|
|
import ThemeToggle from '../../ui/components/theme_toggle_container';
|
2020-08-23 13:56:18 -07:00
|
|
|
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
2021-08-20 13:46:17 -07:00
|
|
|
import { getFeatures } from 'soapbox/utils/features';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2020-06-06 12:57:05 -07:00
|
|
|
const messages = defineMessages({
|
|
|
|
post: { id: 'tabs_bar.post', defaultMessage: 'Post' },
|
|
|
|
});
|
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
class TabsBar extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
history: PropTypes.object.isRequired,
|
|
|
|
onOpenCompose: PropTypes.func,
|
|
|
|
onOpenSidebar: PropTypes.func.isRequired,
|
2020-04-14 14:37:17 -07:00
|
|
|
logo: PropTypes.string,
|
|
|
|
account: ImmutablePropTypes.map,
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
collapsed: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
}
|
|
|
|
|
|
|
|
setRef = ref => {
|
|
|
|
this.node = ref;
|
|
|
|
}
|
|
|
|
|
2020-09-09 12:52:27 -07:00
|
|
|
isHomeActive = (match, location) => {
|
|
|
|
const { pathname } = location;
|
|
|
|
return pathname === '/' || pathname.startsWith('/timeline/');
|
|
|
|
}
|
|
|
|
|
2020-04-14 14:47:35 -07:00
|
|
|
render() {
|
2021-09-12 16:51:39 -07:00
|
|
|
const { account, logo, onOpenCompose, onOpenSidebar, intl } = this.props;
|
2020-07-11 13:22:39 -07:00
|
|
|
const { collapsed } = this.state;
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
const classes = classNames('tabs-bar', {
|
|
|
|
'tabs-bar--collapsed': collapsed,
|
2020-04-14 11:44:40 -07:00
|
|
|
});
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<nav className={classes} ref={this.setRef}>
|
|
|
|
<div className='tabs-bar__container'>
|
|
|
|
<div className='tabs-bar__split tabs-bar__split--left'>
|
2021-09-12 16:51:39 -07:00
|
|
|
{logo && (
|
|
|
|
<Link key='logo' className='tabs-bar__link--logo' to='/' data-preview-title-id='column.home'>
|
|
|
|
<img alt='Logo' src={logo} />
|
|
|
|
<span><FormattedMessage id='tabs_bar.home' defaultMessage='Home' /></span>
|
|
|
|
</Link>
|
|
|
|
)}
|
2020-03-27 13:59:38 -07:00
|
|
|
</div>
|
|
|
|
<div className='tabs-bar__split tabs-bar__split--right'>
|
|
|
|
<div className='tabs-bar__search-container'>
|
|
|
|
<SearchContainer openInRoute />
|
|
|
|
</div>
|
|
|
|
{ account &&
|
2020-07-20 13:34:54 -07:00
|
|
|
<>
|
2020-07-19 17:44:17 -07:00
|
|
|
<ThemeToggle />
|
2020-03-27 13:59:38 -07:00
|
|
|
<div className='tabs-bar__profile'>
|
|
|
|
<Avatar account={account} />
|
2020-04-14 11:44:40 -07:00
|
|
|
<button className='tabs-bar__sidebar-btn' onClick={onOpenSidebar} />
|
2021-03-23 17:06:55 -07:00
|
|
|
<ProfileDropdown account={account} size={34} />
|
2020-03-27 13:59:38 -07:00
|
|
|
</div>
|
2020-06-06 12:57:05 -07:00
|
|
|
<button className='tabs-bar__button-compose button' onClick={onOpenCompose} aria-label={intl.formatMessage(messages.post)}>
|
|
|
|
<span>{intl.formatMessage(messages.post)}</span>
|
2020-03-27 13:59:38 -07:00
|
|
|
</button>
|
2020-07-20 13:34:54 -07:00
|
|
|
</>
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
!account &&
|
|
|
|
<div className='flex'>
|
2020-04-10 17:32:16 -07:00
|
|
|
<Link className='tabs-bar__button button' to='/auth/sign_in'>
|
2020-03-27 13:59:38 -07:00
|
|
|
<FormattedMessage id='account.login' defaultMessage='Log In' />
|
2020-04-10 17:32:16 -07:00
|
|
|
</Link>
|
2020-06-07 14:55:28 -07:00
|
|
|
<Link className='tabs-bar__button button button-alternative-2' to='/'>
|
2020-03-27 13:59:38 -07:00
|
|
|
<FormattedMessage id='account.register' defaultMessage='Sign up' />
|
2020-04-10 17:32:16 -07:00
|
|
|
</Link>
|
2020-03-27 13:59:38 -07:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
);
|
|
|
|
}
|
2020-04-14 11:44:40 -07:00
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
2020-04-01 19:20:47 -07:00
|
|
|
const me = state.get('me');
|
2021-08-20 13:46:17 -07:00
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
return {
|
|
|
|
account: state.getIn(['accounts', me]),
|
2020-08-23 13:56:18 -07:00
|
|
|
logo: getSoapboxConfig(state).get('logo'),
|
2020-03-27 13:59:38 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onOpenCompose() {
|
|
|
|
dispatch(openModal('COMPOSE'));
|
|
|
|
},
|
|
|
|
onOpenSidebar() {
|
|
|
|
dispatch(openSidebar());
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-07-10 03:13:38 -07:00
|
|
|
export default withRouter(injectIntl(
|
2020-10-07 11:08:36 -07:00
|
|
|
connect(mapStateToProps, mapDispatchToProps, null, { forwardRef: true },
|
2021-07-10 03:13:38 -07:00
|
|
|
)(TabsBar)));
|