Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distraction Free: Add missing command in site editor #52868

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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