From 6e95e230e8ab0816ea4ae29757785a935c3a404a Mon Sep 17 00:00:00 2001
From: ilkin-overleaf <100852799+ilkin-overleaf@users.noreply.github.com>
Date: Tue, 20 Feb 2024 17:39:59 +0200
Subject: [PATCH] Merge pull request #17192 from overleaf/ii-dictionary-modal
[web] Remove dictionary word only if request is successful
GitOrigin-RevId: 43ffd0dac3ca9729213cf7901f39094c54806412
---
.../components/dictionary-modal-content.tsx | 55 ++++++++++---------
.../dictionary-modal-content.test.jsx | 14 +++--
2 files changed, 39 insertions(+), 30 deletions(-)
diff --git a/services/web/frontend/js/features/dictionary/components/dictionary-modal-content.tsx b/services/web/frontend/js/features/dictionary/components/dictionary-modal-content.tsx
index cd0af3cd77..4f86611eff 100644
--- a/services/web/frontend/js/features/dictionary/components/dictionary-modal-content.tsx
+++ b/services/web/frontend/js/features/dictionary/components/dictionary-modal-content.tsx
@@ -1,4 +1,4 @@
-import { useCallback } from 'react'
+import { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Alert, Button, Modal } from 'react-bootstrap'
import Icon from '../../../shared/components/icon'
@@ -18,19 +18,24 @@ export default function DictionaryModalContent({
handleHide,
}: DictionaryModalContentProps) {
const { t } = useTranslation()
+ const [learnedWords, setLearnedWords] = useState(ignoredWords.learnedWords)
const { isError, runAsync } = useAsync()
const handleRemove = useCallback(
word => {
- ignoredWords.remove(word)
runAsync(
postJSON('/spelling/unlearn', {
body: {
word,
},
})
- ).catch(debugConsole.error)
+ )
+ .then(() => {
+ ignoredWords.remove(word)
+ setLearnedWords(new Set(ignoredWords.learnedWords))
+ })
+ .catch(debugConsole.error)
},
[runAsync]
)
@@ -46,31 +51,29 @@ export default function DictionaryModalContent({
diff --git a/services/web/test/frontend/features/dictionary/components/dictionary-modal-content.test.jsx b/services/web/test/frontend/features/dictionary/components/dictionary-modal-content.test.jsx
index 072357dd83..6f1c637bba 100644
--- a/services/web/test/frontend/features/dictionary/components/dictionary-modal-content.test.jsx
+++ b/services/web/test/frontend/features/dictionary/components/dictionary-modal-content.test.jsx
@@ -1,5 +1,8 @@
-import { screen, fireEvent } from '@testing-library/react'
-import { expect } from 'chai'
+import {
+ screen,
+ fireEvent,
+ waitForElementToBeRemoved,
+} from '@testing-library/react'
import fetchMock from 'fetch-mock'
import DictionaryModal from '../../../../../frontend/js/features/dictionary/components/dictionary-modal'
import { renderWithEditorContext } from '../../../helpers/render-with-context'
@@ -16,6 +19,7 @@ describe('