From b4d1d247ed19b4d4d22097b84fda81ccab89c7d7 Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Thu, 13 Jan 2022 12:01:19 +0300 Subject: [PATCH] [all] refactoring --- .../mobile/src/controller/Error.jsx | 17 +++++++++++------ .../mobile/src/controller/Error.jsx | 17 +++++++++++------ .../mobile/src/controller/Error.jsx | 16 ++++++++++------ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/apps/documenteditor/mobile/src/controller/Error.jsx b/apps/documenteditor/mobile/src/controller/Error.jsx index 7a9f49a26..16eca5427 100644 --- a/apps/documenteditor/mobile/src/controller/Error.jsx +++ b/apps/documenteditor/mobile/src/controller/Error.jsx @@ -4,20 +4,25 @@ import { f7 } from 'framework7-react'; import { useTranslation } from 'react-i18next'; const ErrorController = inject('storeAppOptions')(({storeAppOptions, LoadingDocument}) => { - const {t} = useTranslation(); - const _t = t("Error", { returnObjects: true }); - useEffect(() => { - Common.Notifications.on('engineCreated', (api) => { - api.asc_registerCallback('asc_onError', onError); - }); + const on_engine_created = k => { k.asc_registerCallback('asc_onError', onError); }; + + const api = Common.EditorApi.get(); + if ( !api ) Common.Notifications.on('engineCreated', on_engine_created); + else on_engine_created(api); + return () => { const api = Common.EditorApi.get(); if ( api ) api.asc_unregisterCallback('asc_onError', onError); + + Common.Notifications.off('engineCreated', on_engine_created); } }); const onError = (id, level, errData) => { + const {t} = useTranslation(); + const _t = t("Error", { returnObjects: true }); + if (id === Asc.c_oAscError.ID.LoadingScriptError) { f7.notification.create({ title: _t.criticalErrorTitle, diff --git a/apps/presentationeditor/mobile/src/controller/Error.jsx b/apps/presentationeditor/mobile/src/controller/Error.jsx index e2784d2c7..839dd126b 100644 --- a/apps/presentationeditor/mobile/src/controller/Error.jsx +++ b/apps/presentationeditor/mobile/src/controller/Error.jsx @@ -4,20 +4,25 @@ import { f7 } from 'framework7-react'; import { useTranslation } from 'react-i18next'; const ErrorController = inject('storeAppOptions')(({storeAppOptions, LoadingDocument}) => { - const {t} = useTranslation(); - const _t = t("Error", { returnObjects: true }); - useEffect(() => { - Common.Notifications.on('engineCreated', (api) => { - api.asc_registerCallback('asc_onError', onError); - }); + const on_engine_created = k => { k.asc_registerCallback('asc_onError', onError); }; + + const api = Common.EditorApi.get(); + if ( !api ) Common.Notifications.on('engineCreated', on_engine_created); + else on_engine_created(api); + return () => { const api = Common.EditorApi.get(); if ( api ) api.asc_unregisterCallback('asc_onError', onError); + + Common.Notifications.off('engineCreated', on_engine_created); } }); const onError = (id, level, errData) => { + const {t} = useTranslation(); + const _t = t("Error", { returnObjects: true }); + if (id === Asc.c_oAscError.ID.LoadingScriptError) { f7.notification.create({ title: _t.criticalErrorTitle, diff --git a/apps/spreadsheeteditor/mobile/src/controller/Error.jsx b/apps/spreadsheeteditor/mobile/src/controller/Error.jsx index 9b5c0deee..94f05d1c3 100644 --- a/apps/spreadsheeteditor/mobile/src/controller/Error.jsx +++ b/apps/spreadsheeteditor/mobile/src/controller/Error.jsx @@ -4,20 +4,24 @@ import { f7 } from 'framework7-react'; import { useTranslation } from 'react-i18next'; const ErrorController = inject('storeAppOptions')(({storeAppOptions, LoadingDocument}) => { - const {t} = useTranslation(); - const _t = t("Error", { returnObjects: true }); - useEffect(() => { - Common.Notifications.on('engineCreated', (api) => { - api.asc_registerCallback('asc_onError', onError); - }); + const on_engine_created = k => { k.asc_registerCallback('asc_onError', onError); }; + + const api = Common.EditorApi.get(); + if ( !api ) Common.Notifications.on('engineCreated', on_engine_created); + else on_engine_created(api); + return () => { const api = Common.EditorApi.get(); if ( api ) api.asc_unregisterCallback('asc_onError', onError); + + Common.Notifications.off('engineCreated', on_engine_created); } }); const onError = (id, level, errData) => { + const {t} = useTranslation(); + const _t = t("Error", { returnObjects: true }); const api = Common.EditorApi.get(); if (id === Asc.c_oAscError.ID.LoadingScriptError) {