import React from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { throttle } from 'lodash'; import Icon from 'soapbox/components/icon'; import classNames from 'classnames'; import Helmet from 'soapbox/components/helmet'; export default class SubNavigation extends React.PureComponent { static propTypes = { message: PropTypes.string, } static contextTypes = { router: PropTypes.object.isRequired, } state = { scrolled: false, } handleBackClick = () => { if (window.history && window.history.length === 1) { this.context.router.history.push('/'); } else { this.context.router.history.goBack(); } } handleBackKeyUp = (e) => { if (e.key === 'Enter') { this.handleClick(); } } componentDidMount() { this.attachScrollListener(); } componentWillUnmount() { this.detachScrollListener(); } attachScrollListener() { window.addEventListener('scroll', this.handleScroll); } detachScrollListener() { window.removeEventListener('scroll', this.handleScroll); } handleScroll = throttle(() => { if (this.node) { const { top } = this.node.getBoundingClientRect(); if (top <= 50) { this.setState({ scrolled: true }); } else { this.setState({ scrolled: false }); } } }, 150, { trailing: true }); setRef = c => { this.node = c; } render() { const { message } = this.props; const { scrolled } = this.state; return (