Skip to content

Commit

Permalink
Distraction Free: Add missing command in site editor (#52868)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong authored Jul 24, 2023
1 parent 81b58d3 commit dad8f92
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions packages/edit-site/src/hooks/commands/use-edit-mode-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useCommandLoader } from '@wordpress/commands';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { store as preferencesStore } from '@wordpress/preferences';
import { store as interfaceStore } from '@wordpress/interface';
import { store as noticesStore } from '@wordpress/notices';

/**
* Internal dependencies
Expand Down Expand Up @@ -137,8 +138,13 @@ function useManipulateDocumentCommands() {
}

function useEditUICommands() {
const { openGeneralSidebar, closeGeneralSidebar, switchEditorMode } =
useDispatch( editSiteStore );
const {
openGeneralSidebar,
closeGeneralSidebar,
setIsInserterOpened,
setIsListViewOpened,
switchEditorMode,
} = useDispatch( editSiteStore );
const { canvasMode, editorMode, activeSidebar } = useSelect(
( select ) => ( {
canvasMode: unlock( select( editSiteStore ) ).getCanvasMode(),
Expand All @@ -150,7 +156,9 @@ function useEditUICommands() {
[]
);
const { openModal } = useDispatch( interfaceStore );
const { toggle } = useDispatch( preferencesStore );
const { get: getPreference } = useSelect( preferencesStore );
const { set: setPreference, toggle } = useDispatch( preferencesStore );
const { createInfoNotice } = useDispatch( noticesStore );

if ( canvasMode !== 'edit' ) {
return { isLoading: false, commands: [] };
Expand Down Expand Up @@ -196,6 +204,29 @@ function useEditUICommands() {
},
} );

commands.push( {
name: 'core/toggle-distraction-free',
label: __( 'Toggle distraction free' ),
icon: cog,
callback: ( { close } ) => {
setPreference( 'core/edit-site', 'fixedToolbar', false );
setIsInserterOpened( false );
setIsListViewOpened( false );
closeGeneralSidebar();
toggle( 'core/edit-site', 'distractionFree' );
createInfoNotice(
getPreference( 'core/edit-site', 'distractionFree' )
? __( 'Distraction free mode turned on.' )
: __( 'Distraction free mode turned off.' ),
{
id: 'core/edit-site/distraction-free-mode/notice',
type: 'snackbar',
}
);
close();
},
} );

commands.push( {
name: 'core/toggle-top-toolbar',
label: __( 'Toggle top toolbar' ),
Expand Down

1 comment on commit dad8f92

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in dad8f92.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5643204019
📝 Reported issues:

Please sign in to comment.