Skip to content

Commit

Permalink
Fix unintentional toggling on of distraction free (#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 committed Jun 29, 2023
1 parent 76e03d7 commit 3b7902e
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 3b7902e

Please sign in to comment.