mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-26 21:52:07 +00:00
a9d7f99446
Writefull editor notification GitOrigin-RevId: 1a5077164682dbec67738af0684d364571802816
29 lines
919 B
TypeScript
29 lines
919 B
TypeScript
import { useEffect, useState } from 'react'
|
|
|
|
/**
|
|
*
|
|
* @param {number} delay how long to wait before checking for grammarly in ms
|
|
* @param {boolean} initialState the initial state we should set grammarlyInstalled to before checking after the delay
|
|
* @returns {boolean} a stateful boolean which is initially false, then updates to reflect whether grammarly is installed after the delay to check
|
|
*/
|
|
export default function useWaitForGrammarlyCheck({
|
|
delay = 3000,
|
|
initialState = false,
|
|
}) {
|
|
const [grammarlyInstalled, setGrammarlyInstalled] = useState(() => {
|
|
return initialState
|
|
})
|
|
|
|
useEffect(() => {
|
|
const timer = setTimeout(
|
|
() => setGrammarlyInstalled(grammarlyExtensionPresent()),
|
|
delay
|
|
)
|
|
return () => clearTimeout(timer)
|
|
}, [delay])
|
|
return grammarlyInstalled
|
|
}
|
|
|
|
function grammarlyExtensionPresent() {
|
|
return !!document.querySelector('grammarly-desktop-integration')
|
|
}
|