🚚(frontend) add utils userAgent

In order to stay DRY, we moved the function
to know if a user is from a firefox browser
from useSaveDoc to utils userAgent.
This commit is contained in:
Anthony LC
2024-10-01 15:42:13 +02:00
committed by Anthony LC
parent 002b9340e3
commit a5e798164c
3 changed files with 6 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ import * as Y from 'yjs';
import { useUpdateDoc } from '@/features/docs/doc-management/';
import { KEY_LIST_DOC_VERSIONS } from '@/features/docs/doc-versioning';
import { isFirefox } from '@/utils/userAgent';
import { toBase64 } from '../utils';
@@ -87,10 +88,7 @@ const useSaveDoc = (docId: string, doc: 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).
*/
const isFirefox =
navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
if (typeof e !== 'undefined' && e.preventDefault && isFirefox) {
if (typeof e !== 'undefined' && e.preventDefault && isFirefox()) {
e.preventDefault();
}
};

View File

@@ -1,2 +1,4 @@
export * from './userAgent';
export * from './string';
export * from './styleBuilder';
export * from './system';

View File

@@ -0,0 +1,2 @@
export const isFirefox = () =>
navigator.userAgent.toLowerCase().indexOf('firefox') > -1;