Skip to content

Commit

Permalink
Fix unintentional toggling on of distraction free (WordPress#52090)
Browse files Browse the repository at this point in the history
* replace toggle with set preference - because I don't read code properly it seems

* remove notification
  • Loading branch information
draganescu authored and sethrubenstein committed Jul 13, 2023
1 parent 61c1b4d commit 2a52999
Showing 1 changed file with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,14 +33,21 @@ 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 hasGlobalStyleVariations = useSelect(
( select ) =>
!! select(
coreStore
).__experimentalGetCurrentThemeGlobalStylesVariations()?.length,
const { set: setPreference } = useDispatch( preferencesStore );
const { hasGlobalStyleVariations, isDistractionFree } = useSelect(
( select ) => ( {
hasGlobalStyleVariations:
!! select(
coreStore
).__experimentalGetCurrentThemeGlobalStylesVariations()?.length,
isDistractionFree: select( preferencesStore ).get(
editSiteStore.name,
'distractionFree'
),
} ),
[]
);
if ( hasGlobalStyleVariations ) {
Expand All @@ -56,15 +64,21 @@ export function SidebarNavigationItemGlobalStyles( props ) {
{ ...props }
onClick={ () => {
// Disable distraction free mode.
toggleFeature( '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.
Expand Down

0 comments on commit 2a52999

Please sign in to comment.