From b3659991b687b9a313706a9180fa2bd0531bc000 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Mon, 9 Oct 2023 10:24:31 +0200 Subject: [PATCH] refactor: handle recording on first load and plugin cache clear --- src/PluginWrapper.js | 54 ++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/PluginWrapper.js b/src/PluginWrapper.js index fb4779a66..b489359c5 100644 --- a/src/PluginWrapper.js +++ b/src/PluginWrapper.js @@ -1,6 +1,5 @@ import { useCacheableSection, CacheableSection } from '@dhis2/app-runtime' import { CenteredContent, CircularLoader, Layer } from '@dhis2/ui' -import postRobot from '@krakenjs/post-robot' import PropTypes from 'prop-types' import React, { useEffect } from 'react' import { Visualization } from './components/Visualization/Visualization.js' @@ -34,17 +33,6 @@ const CacheableSectionWrapper = ({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [cacheNow]) - useEffect(() => { - const listener = postRobot.on( - 'removeCachedData', - // todo: check domain too; differs based on deployment env though - { window: window.parent }, - () => remove() - ) - - return () => listener.cancel() - }, [remove]) - useEffect(() => { // Synchronize cache state on load or prop update // -- a back-up to imperative `removeCachedData` @@ -69,7 +57,8 @@ CacheableSectionWrapper.propTypes = { } const PluginWrapper = (props) => { - const { onInstallationStatusChange, ...propsFromParent } = props + const { onInstallationStatusChange, onPropsReceived, ...propsFromParent } = + props useEffect(() => { // Get & send PWA installation status now @@ -78,27 +67,34 @@ const PluginWrapper = (props) => { }).then(onInstallationStatusChange) }, [onInstallationStatusChange]) - return propsFromParent ? ( -
- - - -
- ) : null + + + + + ) + } else { + return null + } } PluginWrapper.propTypes = { onInstallationStatusChange: PropTypes.func, + onPropsReceived: PropTypes.func, } export default PluginWrapper