Add indicator of unread content to window title when web UI is out of focus (#11560)
Fix #1288master
parent
5f63339744
commit
c09ecbc53e
@ -0,0 +1,10 @@ |
|||||||
|
export const APP_FOCUS = 'APP_FOCUS'; |
||||||
|
export const APP_UNFOCUS = 'APP_UNFOCUS'; |
||||||
|
|
||||||
|
export const focusApp = () => ({ |
||||||
|
type: APP_FOCUS, |
||||||
|
}); |
||||||
|
|
||||||
|
export const unfocusApp = () => ({ |
||||||
|
type: APP_UNFOCUS, |
||||||
|
}); |
@ -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; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
import { Map as ImmutableMap } from 'immutable'; |
||||||
|
import { NOTIFICATIONS_UPDATE } from 'mastodon/actions/notifications'; |
||||||
|
import { TIMELINE_UPDATE } from 'mastodon/actions/timelines'; |
||||||
|
import { APP_FOCUS, APP_UNFOCUS } from 'mastodon/actions/app'; |
||||||
|
|
||||||
|
const initialState = ImmutableMap({ |
||||||
|
focused: true, |
||||||
|
unread: 0, |
||||||
|
}); |
||||||
|
|
||||||
|
export default function missed_updates(state = initialState, action) { |
||||||
|
switch(action.type) { |
||||||
|
case APP_FOCUS: |
||||||
|
return state.set('focused', true).set('unread', 0); |
||||||
|
case APP_UNFOCUS: |
||||||
|
return state.set('focused', false); |
||||||
|
case NOTIFICATIONS_UPDATE: |
||||||
|
case TIMELINE_UPDATE: |
||||||
|
return state.get('focused') ? state : state.update('unread', x => x + 1); |
||||||
|
default: |
||||||
|
return state; |
||||||
|
} |
||||||
|
}; |
Loading…
Reference in new issue