diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index d13e60f6f0..6e8013aebd 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -65,7 +65,7 @@ block content span.sr-only #{translate("close")} .system-message-content(ng-bind-html="htmlContent") - grammarly-warning() + grammarly-warning(delay=10000) include ./editor/main diff --git a/services/web/frontend/js/features/source-editor/components/grammarly-warning.tsx b/services/web/frontend/js/features/source-editor/components/grammarly-warning.tsx index 4d1ca92121..1344e8cd4b 100644 --- a/services/web/frontend/js/features/source-editor/components/grammarly-warning.tsx +++ b/services/web/frontend/js/features/source-editor/components/grammarly-warning.tsx @@ -1,11 +1,16 @@ import { useCallback, useEffect, useState } from 'react' import { Button } from 'react-bootstrap' +import { Nullable } from '../../../../../types/utils' import customLocalStorage from '../../../infrastructure/local-storage' import useScopeValue from '../../../shared/hooks/use-scope-value' import grammarlyExtensionPresent from '../../../shared/utils/grammarly' import getMeta from '../../../utils/meta' -export default function GrammarlyWarning() { +type GrammarlyWarningProps = { + delay: number +} + +export default function GrammarlyWarning({ delay }: GrammarlyWarningProps) { const [show, setShow] = useState(false) const [newSourceEditor] = useScopeValue('editor.newSourceEditor') const [showRichText] = useScopeValue('editor.showRichText') @@ -21,10 +26,29 @@ export default function GrammarlyWarning() { newSourceEditor && !showRichText + let timeoutID: Nullable + if (showGrammarlyWarning) { - setShow(true) + const timeout = window.setTimeout(() => { + setShow(true) + timeoutID = null + }, delay) + + timeoutID = timeout } - }, [grammarly, hasDismissedGrammarlyWarning, newSourceEditor, showRichText]) + + return () => { + if (timeoutID) { + clearTimeout(timeoutID) + } + } + }, [ + grammarly, + hasDismissedGrammarlyWarning, + newSourceEditor, + showRichText, + delay, + ]) const handleClose = useCallback(() => { setShow(false) diff --git a/services/web/frontend/js/features/source-editor/controllers/grammarly-warning-controller.js b/services/web/frontend/js/features/source-editor/controllers/grammarly-warning-controller.js index e1a9679394..a96ae1b581 100644 --- a/services/web/frontend/js/features/source-editor/controllers/grammarly-warning-controller.js +++ b/services/web/frontend/js/features/source-editor/controllers/grammarly-warning-controller.js @@ -5,5 +5,5 @@ import GrammarlyWarning from '../components/grammarly-warning' App.component( 'grammarlyWarning', - react2angular(rootContext.use(GrammarlyWarning)) + react2angular(rootContext.use(GrammarlyWarning), ['delay']) ) diff --git a/services/web/test/frontend/features/source-editor/components/grammarly-warning.test.js b/services/web/test/frontend/features/source-editor/components/grammarly-warning.test.js index f1b5c1cc1e..ff9a5c7f42 100644 --- a/services/web/test/frontend/features/source-editor/components/grammarly-warning.test.js +++ b/services/web/test/frontend/features/source-editor/components/grammarly-warning.test.js @@ -29,7 +29,7 @@ describe('', function () { grammarlyStub.returns(true) window.metaAttributesCache.set('ol-showNewSourceEditorOption', true) - renderWithEditorContext(, { + renderWithEditorContext(, { scope: { editor: { newSourceEditor: true, @@ -48,7 +48,7 @@ describe('', function () { grammarlyStub.returns(false) window.metaAttributesCache.set('ol-showNewSourceEditorOption', true) - renderWithEditorContext(, { + renderWithEditorContext(, { scope: { editor: { newSourceEditor: true, @@ -70,7 +70,7 @@ describe('', function () { localStorage.setItem('editor.has_dismissed_grammarly_warning', true) window.metaAttributesCache.set('ol-showNewSourceEditorOption', true) - renderWithEditorContext(, { + renderWithEditorContext(, { scope: { editor: { newSourceEditor: true, @@ -91,7 +91,7 @@ describe('', function () { grammarlyStub.returns(true) window.metaAttributesCache.set('ol-showNewSourceEditorOption', false) - renderWithEditorContext() + renderWithEditorContext() await waitFor(() => { expect( @@ -106,7 +106,7 @@ describe('', function () { grammarlyStub.returns(true) window.metaAttributesCache.set('ol-showNewSourceEditorOption', true) - renderWithEditorContext(, { + renderWithEditorContext(, { scope: { editor: { newSourceEditor: false, @@ -127,7 +127,7 @@ describe('', function () { grammarlyStub.returns(true) window.metaAttributesCache.set('ol-showNewSourceEditorOption', true) - renderWithEditorContext(, { + renderWithEditorContext(, { scope: { editor: { newSourceEditor: true, @@ -149,7 +149,7 @@ describe('', function () { grammarlyStub.returns(true) window.metaAttributesCache.set('ol-showNewSourceEditorOption', true) - renderWithEditorContext(, { + renderWithEditorContext(, { scope: { editor: { newSourceEditor: true,