gab-social/app/javascript/gabsocial/features/ui/util/page_title.js

42 lines
889 B
JavaScript
Raw Normal View History

2020-04-11 23:29:19 +01:00
import isEqual from 'lodash.isequal'
export default class PageTitle extends PureComponent {
static propTypes = {
2020-04-22 06:00:11 +01:00
badge: PropTypes.oneOfType([
2020-04-11 23:29:19 +01:00
PropTypes.number,
PropTypes.string,
]),
2020-04-22 06:00:11 +01:00
path: PropTypes.oneOfType([
2020-04-23 07:13:29 +01:00
PropTypes.string,
2020-04-11 23:29:19 +01:00
PropTypes.array,
]),
}
componentDidMount() {
this.updatePageTitle(this.props)
}
componentDidUpdate(prevProps) {
if (this.props.badge !== prevProps.badge || !isEqual(this.props.path, prevProps.path)) {
this.updatePageTitle(this.props)
}
}
updatePageTitle = ({ badge, path}) => {
const site = 'Gab'
let realPath = Array.isArray(path) ? path.join(' / ') : path
realPath = realPath.trim()
const realBadge = !!badge ? `(${badge})` : ''
const title = `${realBadge} ${realPath} / ${site}`.trim()
document.title = title
}
render() {
return null
}
}