From 8aab007ad13e7a8cd649a11ef30844d53bd8fc81 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Tue, 1 Apr 2025 14:51:48 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20do=20not=20display=20f?= =?UTF-8?q?irefox=20modal=20if=20not=20necessary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is necessary to display the firefox modal only if the user has something to save. --- .../features/docs/doc-editor/hook/useSaveDoc.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/hook/useSaveDoc.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/hook/useSaveDoc.tsx index 8a5a41c0..26e51891 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/hook/useSaveDoc.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/hook/useSaveDoc.tsx @@ -43,20 +43,22 @@ const useSaveDoc = (docId: string, yDoc: Y.Doc, canSave: boolean) => { const saveDoc = useCallback(() => { if (!canSave || !isLocalChange) { - return; + return false; } updateDoc({ id: docId, content: toBase64(Y.encodeStateAsUpdate(yDoc)), }); + + return true; }, [canSave, yDoc, docId, isLocalChange, updateDoc]); const router = useRouter(); useEffect(() => { const onSave = (e?: Event) => { - saveDoc(); + const isSaving = saveDoc(); /** * Firefox does not trigger the request everytime the user leaves the page. @@ -65,7 +67,12 @@ const useSaveDoc = (docId: string, yDoc: Y.Doc, canSave: boolean) => { * if he wants to leave the page, by adding the popup, we let the time to the * request to be sent, and intercepted by the service worker (for the offline part). */ - if (typeof e !== 'undefined' && e.preventDefault && isFirefox()) { + if ( + isSaving && + typeof e !== 'undefined' && + e.preventDefault && + isFirefox() + ) { e.preventDefault(); } };