2022-11-15 13:10:05 -05:00
|
|
|
import { useCallback, useEffect, useState } from 'react'
|
|
|
|
import { Button } from 'react-bootstrap'
|
2022-11-24 10:50:43 -05:00
|
|
|
import { Nullable } from '../../../../../types/utils'
|
2022-11-15 13:10:05 -05:00
|
|
|
import customLocalStorage from '../../../infrastructure/local-storage'
|
|
|
|
import useScopeValue from '../../../shared/hooks/use-scope-value'
|
|
|
|
import grammarlyExtensionPresent from '../../../shared/utils/grammarly'
|
|
|
|
|
2022-11-24 10:50:43 -05:00
|
|
|
type GrammarlyWarningProps = {
|
|
|
|
delay: number
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function GrammarlyWarning({ delay }: GrammarlyWarningProps) {
|
2022-11-15 13:10:05 -05:00
|
|
|
const [show, setShow] = useState(false)
|
|
|
|
const [newSourceEditor] = useScopeValue('editor.newSourceEditor')
|
|
|
|
const grammarly = grammarlyExtensionPresent()
|
|
|
|
const hasDismissedGrammarlyWarning = customLocalStorage.getItem(
|
|
|
|
'editor.has_dismissed_grammarly_warning'
|
|
|
|
)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const showGrammarlyWarning =
|
2023-08-15 05:53:00 -04:00
|
|
|
!hasDismissedGrammarlyWarning && grammarly && newSourceEditor
|
2022-11-15 13:10:05 -05:00
|
|
|
|
2022-11-24 10:50:43 -05:00
|
|
|
let timeoutID: Nullable<number>
|
|
|
|
|
2022-11-15 13:10:05 -05:00
|
|
|
if (showGrammarlyWarning) {
|
2022-11-24 10:50:43 -05:00
|
|
|
const timeout = window.setTimeout(() => {
|
|
|
|
setShow(true)
|
|
|
|
timeoutID = null
|
|
|
|
}, delay)
|
|
|
|
|
|
|
|
timeoutID = timeout
|
|
|
|
}
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
if (timeoutID) {
|
|
|
|
clearTimeout(timeoutID)
|
|
|
|
}
|
2022-11-15 13:10:05 -05:00
|
|
|
}
|
2023-08-15 05:53:00 -04:00
|
|
|
}, [grammarly, hasDismissedGrammarlyWarning, newSourceEditor, delay])
|
2022-11-15 13:10:05 -05:00
|
|
|
|
|
|
|
const handleClose = useCallback(() => {
|
|
|
|
setShow(false)
|
|
|
|
customLocalStorage.setItem('editor.has_dismissed_grammarly_warning', true)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
if (!show) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="alert alert-info grammarly-warning" role="alert">
|
|
|
|
<Button
|
|
|
|
className="close"
|
|
|
|
data-dismiss="alert"
|
|
|
|
aria-label="Close"
|
|
|
|
onClick={handleClose}
|
2023-04-04 09:47:28 -04:00
|
|
|
bsStyle={null}
|
2022-11-15 13:10:05 -05:00
|
|
|
>
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</Button>
|
|
|
|
<div className="warning-content">
|
|
|
|
A browser extension, for example Grammarly, may be slowing down
|
|
|
|
Overleaf.{' '}
|
|
|
|
<a
|
|
|
|
className="warning-link"
|
|
|
|
href="/learn/how-to/Use_Grammarly_with_Overleaf#Performance_issues"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
Find out how to avoid this
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|