From ba0ac629376bebe2aa85f0a294ae59ec2905dc2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Andrei?= Date: Wed, 3 Apr 2024 17:43:45 -0300 Subject: [PATCH] Force load of Vlibras in Storybook --- packages/volto-vlibras/src/components/Libras.jsx | 14 ++++++++++---- .../src/components/Libras.stories.jsx | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/volto-vlibras/src/components/Libras.jsx b/packages/volto-vlibras/src/components/Libras.jsx index ec0b519..c6780e1 100644 --- a/packages/volto-vlibras/src/components/Libras.jsx +++ b/packages/volto-vlibras/src/components/Libras.jsx @@ -5,10 +5,13 @@ const widgetSrc = 'https://vlibras.gov.br/app'; const scriptId = 'VLibras'; const scriptSrc = `https://vlibras.gov.br/app/vlibras-plugin.js`; -const loadVLibras = (callback) => { +const loadVLibras = (callback, force) => { const existingScript = document.getElementById(scriptId); if (existingScript && callback) { callback(true); + if (force) { + window.onload(); + } } else { if (callback) callback(false); const script = document.createElement('script'); @@ -20,6 +23,9 @@ const loadVLibras = (callback) => { if (callback) callback(true); if (typeof window !== 'undefined') { new window.VLibras.Widget(widgetSrc); + if (force) { + window.onload(); + } } }; } @@ -28,12 +34,12 @@ const loadVLibras = (callback) => { const Libras = (props) => { const [loaded, setLoaded] = useState(false); const [status, setStatus] = useState('enabled'); - const { location } = props; + const { location, force } = props; const pathName = location.pathname; useEffect(() => { - loadVLibras(setLoaded); - }, [loaded]); + loadVLibras(setLoaded, force); + }, [loaded, force]); useEffect(() => { // Disable widget on non content routes diff --git a/packages/volto-vlibras/src/components/Libras.stories.jsx b/packages/volto-vlibras/src/components/Libras.stories.jsx index 0b09d46..ca25fcc 100644 --- a/packages/volto-vlibras/src/components/Libras.stories.jsx +++ b/packages/volto-vlibras/src/components/Libras.stories.jsx @@ -22,6 +22,7 @@ export default { location: { pathname: '/', }, + force: true, }, };