From f7780a2c7e715698086bb5d6e4154ed6c161b059 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 7 Dec 2021 17:13:46 +0400 Subject: [PATCH] Check isActive state locally in components --- .../src/components/welcome-guide/editor.js | 11 ++++++- .../src/components/welcome-guide/index.js | 31 ++++--------------- .../src/components/welcome-guide/styles.js | 20 +++++++++++- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/packages/edit-site/src/components/welcome-guide/editor.js b/packages/edit-site/src/components/welcome-guide/editor.js index 680423118eaeb1..daef61efa4b8b4 100644 --- a/packages/edit-site/src/components/welcome-guide/editor.js +++ b/packages/edit-site/src/components/welcome-guide/editor.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { useDispatch } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; import { Guide } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { createInterpolateElement } from '@wordpress/element'; @@ -15,6 +15,15 @@ import { store as editSiteStore } from '../../store'; export default function WelcomeGuideEditor() { const { toggleFeature } = useDispatch( editSiteStore ); + const isActive = useSelect( + ( select ) => select( editSiteStore ).isFeatureActive( 'welcomeGuide' ), + [] + ); + + if ( ! isActive ) { + return null; + } + return ( { - const sidebar = select( interfaceStore ).getActiveComplementaryArea( - editSiteStore.name - ); - const isStylesSidebar = sidebar === 'edit-site/global-styles'; - const feature = isStylesSidebar ? 'welcomeGuideStyles' : 'welcomeGuide'; - - return { - isActive: select( editSiteStore ).isFeatureActive( feature ), - isStylesOpen: isStylesSidebar, - }; - }, [] ); - - if ( ! isActive ) { - return null; - } - - return isStylesOpen ? : ; + return ( + <> + + + + ); } diff --git a/packages/edit-site/src/components/welcome-guide/styles.js b/packages/edit-site/src/components/welcome-guide/styles.js index 1dae8045535fbc..8ca4dc0cbe9b1c 100644 --- a/packages/edit-site/src/components/welcome-guide/styles.js +++ b/packages/edit-site/src/components/welcome-guide/styles.js @@ -1,9 +1,10 @@ /** * WordPress dependencies */ -import { useDispatch } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; import { ExternalLink, Guide } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; +import { store as interfaceStore } from '@wordpress/interface'; /** * Internal dependencies @@ -14,6 +15,23 @@ import { store as editSiteStore } from '../../store'; export default function WelcomeGuideStyles() { const { toggleFeature } = useDispatch( editSiteStore ); + const { isActive, isStylesOpen } = useSelect( ( select ) => { + const sidebar = select( interfaceStore ).getActiveComplementaryArea( + editSiteStore.name + ); + + return { + isActive: select( editSiteStore ).isFeatureActive( + 'welcomeGuideStyles' + ), + isStylesOpen: sidebar === 'edit-site/global-styles', + }; + }, [] ); + + if ( ! isActive || ! isStylesOpen ) { + return null; + } + return (