From a5e798164c0c9851fd3aecf4769caca719d8127a Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Tue, 1 Oct 2024 15:42:13 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A(frontend)=20add=20utils=20userAgen?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to stay DRY, we moved the function to know if a user is from a firefox browser from useSaveDoc to utils userAgent. --- .../src/features/docs/doc-editor/hook/useSaveDoc.tsx | 6 ++---- src/frontend/apps/impress/src/utils/index.ts | 2 ++ src/frontend/apps/impress/src/utils/userAgent.ts | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 src/frontend/apps/impress/src/utils/userAgent.ts 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 0a21cd45..ca1ed005 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 @@ -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(); } }; diff --git a/src/frontend/apps/impress/src/utils/index.ts b/src/frontend/apps/impress/src/utils/index.ts index 559df58c..4f823731 100644 --- a/src/frontend/apps/impress/src/utils/index.ts +++ b/src/frontend/apps/impress/src/utils/index.ts @@ -1,2 +1,4 @@ +export * from './userAgent'; export * from './string'; +export * from './styleBuilder'; export * from './system'; diff --git a/src/frontend/apps/impress/src/utils/userAgent.ts b/src/frontend/apps/impress/src/utils/userAgent.ts new file mode 100644 index 00000000..fa30acf2 --- /dev/null +++ b/src/frontend/apps/impress/src/utils/userAgent.ts @@ -0,0 +1,2 @@ +export const isFirefox = () => + navigator.userAgent.toLowerCase().indexOf('firefox') > -1;