mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
a555f0d309
* Added project name, pdf toggle and share project buttons to navigation toolbar * Added PropTypes check to `useChatContext()` * React context updates for project name/rename, pdf view and share moda * Hide PDF button when pdfLayout != 'flat' GitOrigin-RevId: 3f4a1b072259df7148d3417cd22116702bdd79ac
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
import { useEffect, useState } from 'react'
|
|
|
|
let titleIsFlashing = false
|
|
let originalTitle
|
|
let flashIntervalHandle
|
|
|
|
function flashTitle(message) {
|
|
if (document.hasFocus() || titleIsFlashing) {
|
|
return
|
|
}
|
|
|
|
function swapTitle() {
|
|
if (window.document.title === originalTitle) {
|
|
window.document.title = message
|
|
} else {
|
|
window.document.title = originalTitle
|
|
}
|
|
}
|
|
|
|
originalTitle = window.document.title
|
|
window.document.title = message
|
|
titleIsFlashing = true
|
|
flashIntervalHandle = setInterval(swapTitle, 800)
|
|
}
|
|
|
|
function stopFlashingTitle() {
|
|
if (!titleIsFlashing) {
|
|
return
|
|
}
|
|
|
|
clearInterval(flashIntervalHandle)
|
|
window.document.title = originalTitle
|
|
originalTitle = undefined
|
|
titleIsFlashing = false
|
|
}
|
|
|
|
function setTitle(title) {
|
|
if (titleIsFlashing) {
|
|
originalTitle = title
|
|
} else {
|
|
window.document.title = title
|
|
}
|
|
}
|
|
|
|
function useBrowserWindow() {
|
|
const [hasFocus, setHasFocus] = useState(document.hasFocus())
|
|
|
|
useEffect(() => {
|
|
function handleFocusEvent() {
|
|
setHasFocus(true)
|
|
}
|
|
|
|
function handleBlurEvent() {
|
|
setHasFocus(false)
|
|
}
|
|
|
|
window.addEventListener('focus', handleFocusEvent)
|
|
window.addEventListener('blur', handleBlurEvent)
|
|
return () => {
|
|
window.removeEventListener('focus', handleFocusEvent)
|
|
window.removeEventListener('blur', handleBlurEvent)
|
|
}
|
|
}, [])
|
|
|
|
return { hasFocus, flashTitle, stopFlashingTitle, setTitle }
|
|
}
|
|
|
|
export default useBrowserWindow
|