From 792c86061e925c7722379484c9badb6796fb27bc Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Wed, 28 Jun 2023 22:41:26 +0300 Subject: [PATCH 1/2] replace toggle with set preference - because I don't read code properly it seems --- .../sidebar-navigation-screen-global-styles/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js index c10de840e8d478..13abf27e425037 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js @@ -16,6 +16,7 @@ import { BlockEditorProvider } from '@wordpress/block-editor'; import { humanTimeDiff } from '@wordpress/date'; import { useCallback } from '@wordpress/element'; import { store as noticesStore } from '@wordpress/notices'; +import { store as preferencesStore } from '@wordpress/preferences'; /** * Internal dependencies @@ -32,9 +33,10 @@ import useGlobalStylesRevisions from '../global-styles/screen-revisions/use-glob const noop = () => {}; export function SidebarNavigationItemGlobalStyles( props ) { - const { openGeneralSidebar, toggleFeature } = useDispatch( editSiteStore ); + const { openGeneralSidebar } = useDispatch( editSiteStore ); const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); const { createNotice } = useDispatch( noticesStore ); + const { set: setPreference } = useDispatch( preferencesStore ); const hasGlobalStyleVariations = useSelect( ( select ) => !! select( @@ -56,7 +58,7 @@ export function SidebarNavigationItemGlobalStyles( props ) { { ...props } onClick={ () => { // Disable distraction free mode. - toggleFeature( 'distractionFree', false ); + setPreference( editSiteStore.name, 'distractionFree', false ); createNotice( 'info', __( 'Distraction free mode turned off' ), From dedad7d664f6d30ddf41d892a1cce5bf5f8bc731 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Wed, 28 Jun 2023 22:53:58 +0300 Subject: [PATCH 2/2] remove notification --- .../index.js | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js index 13abf27e425037..06278590696cbc 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js @@ -37,11 +37,17 @@ export function SidebarNavigationItemGlobalStyles( props ) { const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); const { createNotice } = useDispatch( noticesStore ); const { set: setPreference } = useDispatch( preferencesStore ); - const hasGlobalStyleVariations = useSelect( - ( select ) => - !! select( - coreStore - ).__experimentalGetCurrentThemeGlobalStylesVariations()?.length, + const { hasGlobalStyleVariations, isDistractionFree } = useSelect( + ( select ) => ( { + hasGlobalStyleVariations: + !! select( + coreStore + ).__experimentalGetCurrentThemeGlobalStylesVariations()?.length, + isDistractionFree: select( preferencesStore ).get( + editSiteStore.name, + 'distractionFree' + ), + } ), [] ); if ( hasGlobalStyleVariations ) { @@ -58,15 +64,21 @@ export function SidebarNavigationItemGlobalStyles( props ) { { ...props } onClick={ () => { // Disable distraction free mode. - setPreference( editSiteStore.name, 'distractionFree', false ); - createNotice( - 'info', - __( 'Distraction free mode turned off' ), - { - isDismissible: true, - type: 'snackbar', - } - ); + if ( isDistractionFree ) { + setPreference( + editSiteStore.name, + 'distractionFree', + false + ); + createNotice( + 'info', + __( 'Distraction free mode turned off' ), + { + isDismissible: true, + type: 'snackbar', + } + ); + } // Switch to edit mode. setCanvasMode( 'edit' ); // Open global styles sidebar.