import React from 'react'; import PropTypes from 'prop-types'; import { NavLink, withRouter } from 'react-router-dom'; import { FormattedMessage, injectIntl } from 'react-intl'; import { throttle } from 'lodash'; import { connect } from 'react-redux'; import { me } from '../../../initial_state'; import classNames from 'classnames'; import NotificationsCounterIcon from './notifications_counter_icon'; import SearchContainer from 'gabsocial/features/compose/containers/search_container'; import Avatar from '../../../components/avatar'; import ActionBar from 'gabsocial/features/compose/components/action_bar'; import { openModal } from '../../../actions/modal'; import { openSidebar } from '../../../actions/sidebar'; export const privateLinks = [ , , , , , ]; export const publicLinks = [ , , , ]; @withRouter class TabsBar extends React.PureComponent { static propTypes = { intl: PropTypes.object.isRequired, history: PropTypes.object.isRequired, onOpenCompose: PropTypes.func, onOpenSidebar: PropTypes.func.isRequired, } state = { collapsed: false, } static contextTypes = { router: PropTypes.object, } lastScrollTop = 0; componentDidMount () { this.window = window; this.documentElement = document.scrollingElement || document.documentElement; this.attachScrollListener(); // Handle initial scroll posiiton this.handleScroll(); } componentWillUnmount () { this.detachScrollListener(); } setRef = ref => { this.node = ref; } attachScrollListener () { this.window.addEventListener('scroll', this.handleScroll); } detachScrollListener () { this.window.removeEventListener('scroll', this.handleScroll); } handleScroll = throttle(() => { if (this.window) { const { pageYOffset, innerWidth } = this.window; if (innerWidth > 895) return; const { scrollTop } = this.documentElement; let st = pageYOffset || scrollTop; if (st > this.lastScrollTop){ let offset = st - this.lastScrollTop; if (offset > 50) this.setState({collapsed: true}); } else { let offset = this.lastScrollTop - st; if (offset > 50) this.setState({collapsed: false}); } this.lastScrollTop = st <= 0 ? 0 : st; } }, 150, { trailing: true, }); render () { const { intl: { formatMessage }, account, onOpenCompose, onOpenSidebar } = this.props; const { collapsed } = this.state; const links = account ? privateLinks : publicLinks; const pathname = this.context.router.route.location.pathname || ''; let pathTitle = ''; if (pathname.includes('/home')) { pathTitle = 'Home'; } else if (pathname.includes('/timeline/all')) { pathTitle = 'All'; } else if (pathname.includes('/group')) { pathTitle = 'Groups'; } else if (pathname.includes('/tags')) { pathTitle = 'Tags'; } else if (pathname.includes('/list')) { pathTitle = 'Lists'; } else if (pathname.includes('/notifications')) { pathTitle = 'Notifications'; } else if (pathname.includes('/search')) { pathTitle = 'Search'; } else if (pathname.includes('/follow_requests')) { pathTitle = 'Requests'; } else if (pathname.includes('/blocks')) { pathTitle = 'Blocks'; } else if (pathname.includes('/domain_blocks')) { pathTitle = 'Domain Blocks'; } else if (pathname.includes('/mutes')) { pathTitle = 'Mutes'; } else { pathTitle = 'Profile'; } const classes = classNames('tabs-bar', { 'tabs-bar--collapsed': collapsed, }) return ( ); } } const mapStateToProps = state => { return { account: state.getIn(['accounts', me]), }; }; const mapDispatchToProps = (dispatch) => ({ onOpenCompose() { dispatch(openModal('COMPOSE')); }, onOpenSidebar() { dispatch(openSidebar()); }, }); export default injectIntl( connect(mapStateToProps, mapDispatchToProps, null, { forwardRef: true } )(TabsBar))