about summary refs log tree commit diff
path: root/app/javascript/mastodon/features/ui/components/document_title.js
blob: cd081b20c7e2c7c2ad30659ae3ce2d38cfe0b355 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { PureComponent } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { title } from 'mastodon/initial_state';

const mapStateToProps = state => ({
  unread: state.getIn(['missed_updates', 'unread']),
});

export default @connect(mapStateToProps)
class DocumentTitle extends PureComponent {

  static propTypes = {
    unread: PropTypes.number.isRequired,
  };

  componentDidMount () {
    this._sideEffects();
  }

  componentDidUpdate() {
    this._sideEffects();
  }

  _sideEffects () {
    const { unread } = this.props;

    if (unread > 99) {
      document.title = `(*) ${title}`;
    } else if (unread > 0) {
      document.title = `(${unread}) ${title}`;
    } else {
      document.title = title;
    }
  }

  render () {
    return null;
  }

}