2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-04-11 23:29:19 +01:00
|
|
|
import isEqual from 'lodash.isequal'
|
2020-08-12 23:54:33 +01:00
|
|
|
import { APP_NAME } from '../../../constants'
|
2020-04-11 23:29:19 +01:00
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
class PageTitle extends React.PureComponent {
|
2020-04-11 23:29:19 +01:00
|
|
|
|
|
|
|
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}) => {
|
2020-12-06 05:14:43 +00:00
|
|
|
let realPath = Array.isArray(path) ? path.join(' / ') : `${path}`
|
2020-04-11 23:29:19 +01:00
|
|
|
realPath = realPath.trim()
|
|
|
|
|
|
|
|
const realBadge = !!badge ? `(${badge})` : ''
|
|
|
|
|
2020-08-12 23:54:33 +01:00
|
|
|
const title = `${realBadge} ${realPath} / ${APP_NAME}`.trim()
|
2020-04-11 23:29:19 +01:00
|
|
|
|
|
|
|
document.title = title
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return null
|
|
|
|
}
|
2020-08-12 23:54:33 +01:00
|
|
|
|
2020-04-11 23:29:19 +01:00
|
|
|
}
|
2020-08-12 23:54:33 +01:00
|
|
|
|
|
|
|
PageTitle.propTypes = {
|
|
|
|
badge: PropTypes.oneOfType([
|
|
|
|
PropTypes.number,
|
|
|
|
PropTypes.string,
|
|
|
|
]),
|
|
|
|
path: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.array,
|
|
|
|
]),
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PageTitle
|