Skip to content

Commit 8aab007

Browse files
committed
🐛(frontend) do not display firefox modal if not necessary
It is necessary to display the firefox modal only if the user has something to save.
1 parent cde3de4 commit 8aab007

File tree

1 file changed

+10
-3
lines changed
  • src/frontend/apps/impress/src/features/docs/doc-editor/hook

1 file changed

+10
-3
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/hook/useSaveDoc.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,22 @@ const useSaveDoc = (docId: string, yDoc: Y.Doc, canSave: boolean) => {
4343

4444
const saveDoc = useCallback(() => {
4545
if (!canSave || !isLocalChange) {
46-
return;
46+
return false;
4747
}
4848

4949
updateDoc({
5050
id: docId,
5151
content: toBase64(Y.encodeStateAsUpdate(yDoc)),
5252
});
53+
54+
return true;
5355
}, [canSave, yDoc, docId, isLocalChange, updateDoc]);
5456

5557
const router = useRouter();
5658

5759
useEffect(() => {
5860
const onSave = (e?: Event) => {
59-
saveDoc();
61+
const isSaving = saveDoc();
6062

6163
/**
6264
* 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) => {
6567
* if he wants to leave the page, by adding the popup, we let the time to the
6668
* request to be sent, and intercepted by the service worker (for the offline part).
6769
*/
68-
if (typeof e !== 'undefined' && e.preventDefault && isFirefox()) {
70+
if (
71+
isSaving &&
72+
typeof e !== 'undefined' &&
73+
e.preventDefault &&
74+
isFirefox()
75+
) {
6976
e.preventDefault();
7077
}
7178
};

0 commit comments

Comments
 (0)