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 and tellthemachines committed Jul 25, 2023
1 parent 218ce78 commit 2046e1b
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

0 comments on commit 2046e1b

Please sign in to comment.