diff options
Diffstat (limited to 'app/javascript/mastodon/features/ui/components/document_title.js')
-rw-r--r-- | app/javascript/mastodon/features/ui/components/document_title.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/app/javascript/mastodon/features/ui/components/document_title.js b/app/javascript/mastodon/features/ui/components/document_title.js new file mode 100644 index 000000000..cd081b20c --- /dev/null +++ b/app/javascript/mastodon/features/ui/components/document_title.js @@ -0,0 +1,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; + } + +} |