From ad9c5d9b2ce2d6e6562186b1755ec9c8c5a483d4 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 8 Dec 2021 17:23:24 +0000 Subject: [PATCH] Global Styles: Add Welcome Guide toggle (#37180) * Global Styles: Add Welcome Guide toggle * Check isActive state locally in components --- .../sidebar/global-styles-sidebar.js | 8 +++++ .../src/components/welcome-guide/editor.js | 11 ++++++- .../src/components/welcome-guide/index.js | 31 ++++--------------- .../src/components/welcome-guide/styles.js | 20 +++++++++++- .../src/plugins/welcome-guide-menu-item.js | 18 ++--------- 5 files changed, 45 insertions(+), 43 deletions(-) diff --git a/packages/edit-site/src/components/sidebar/global-styles-sidebar.js b/packages/edit-site/src/components/sidebar/global-styles-sidebar.js index daed883cbca98..add957375f1e2 100644 --- a/packages/edit-site/src/components/sidebar/global-styles-sidebar.js +++ b/packages/edit-site/src/components/sidebar/global-styles-sidebar.js @@ -4,15 +4,18 @@ import { DropdownMenu, FlexItem, FlexBlock, Flex } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { styles, moreVertical } from '@wordpress/icons'; +import { useDispatch } from '@wordpress/data'; /** * Internal dependencies */ import DefaultSidebar from './default-sidebar'; import { GlobalStylesUI, useGlobalStylesReset } from '../global-styles'; +import { store as editSiteStore } from '../../store'; export default function GlobalStylesSidebar() { const [ canReset, onReset ] = useGlobalStylesReset(); + const { toggleFeature } = useDispatch( editSiteStore ); return ( + toggleFeature( 'welcomeGuideStyles' ), + }, ] } /> diff --git a/packages/edit-site/src/components/welcome-guide/editor.js b/packages/edit-site/src/components/welcome-guide/editor.js index 680423118eaeb..daef61efa4b8b 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 a9b113d8315a1..8381225246dad 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 ( { - const sidebar = select( interfaceStore ).getActiveComplementaryArea( - editSiteStore.name - ); - - return sidebar === 'edit-site/global-styles'; - }, [] ); return ( - - toggleFeature( - isStylesOpen ? 'welcomeGuideStyles' : 'welcomeGuide' - ) - } - > + toggleFeature( 'welcomeGuide' ) }> { __( 'Welcome Guide' ) } );