🐛(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.
This commit is contained in:
@@ -43,20 +43,22 @@ const useSaveDoc = (docId: string, yDoc: Y.Doc, canSave: boolean) => {
|
|||||||
|
|
||||||
const saveDoc = useCallback(() => {
|
const saveDoc = useCallback(() => {
|
||||||
if (!canSave || !isLocalChange) {
|
if (!canSave || !isLocalChange) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDoc({
|
updateDoc({
|
||||||
id: docId,
|
id: docId,
|
||||||
content: toBase64(Y.encodeStateAsUpdate(yDoc)),
|
content: toBase64(Y.encodeStateAsUpdate(yDoc)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
}, [canSave, yDoc, docId, isLocalChange, updateDoc]);
|
}, [canSave, yDoc, docId, isLocalChange, updateDoc]);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onSave = (e?: Event) => {
|
const onSave = (e?: Event) => {
|
||||||
saveDoc();
|
const isSaving = saveDoc();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Firefox does not trigger the request everytime the user leaves the page.
|
* 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
|
* 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).
|
* 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();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user