-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Command center: Add another batch of commands to the site editor #51832
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,22 @@ | |
* WordPress dependencies | ||
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { trash, backup, layout, page } from '@wordpress/icons'; | ||
import { __, isRTL } from '@wordpress/i18n'; | ||
import { | ||
code, | ||
cog, | ||
trash, | ||
backup, | ||
layout, | ||
page, | ||
drawerLeft, | ||
drawerRight, | ||
blockDefault, | ||
} from '@wordpress/icons'; | ||
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'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -106,10 +118,102 @@ function useEditModeCommandLoader() { | |
}; | ||
} | ||
|
||
function useEditUICommandLoader() { | ||
const { openGeneralSidebar, closeGeneralSidebar, switchEditorMode } = | ||
useDispatch( editSiteStore ); | ||
const { canvasMode, editorMode, activeSidebar } = useSelect( | ||
( select ) => ( { | ||
isPage: select( editSiteStore ).isPage(), | ||
hasPageContentFocus: select( editSiteStore ).hasPageContentFocus(), | ||
canvasMode: unlock( select( editSiteStore ) ).getCanvasMode(), | ||
editorMode: select( editSiteStore ).getEditorMode(), | ||
activeSidebar: select( interfaceStore ).getActiveComplementaryArea( | ||
editSiteStore.name | ||
), | ||
} ), | ||
[] | ||
); | ||
const { toggle } = useDispatch( preferencesStore ); | ||
|
||
if ( canvasMode !== 'edit' ) { | ||
return { isLoading: false, commands: [] }; | ||
} | ||
|
||
const commands = []; | ||
|
||
commands.push( { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to --edit
I had the tab opened for a while and missed @jasmussen similar comment 😆 |
||
name: 'core/open-settings-sidebar', | ||
label: __( 'Toggle settings sidebar' ), | ||
icon: isRTL() ? drawerLeft : drawerRight, | ||
callback: ( { close } ) => { | ||
close(); | ||
if ( activeSidebar === 'edit-site/template' ) { | ||
closeGeneralSidebar(); | ||
} else { | ||
openGeneralSidebar( 'edit-site/template' ); | ||
} | ||
}, | ||
} ); | ||
|
||
commands.push( { | ||
name: 'core/open-block-inspector', | ||
label: __( 'Toggle block inspector' ), | ||
icon: blockDefault, | ||
callback: ( { close } ) => { | ||
close(); | ||
if ( activeSidebar === 'edit-site/block-inspector' ) { | ||
closeGeneralSidebar(); | ||
} else { | ||
openGeneralSidebar( 'edit-site/block-inspector' ); | ||
} | ||
}, | ||
} ); | ||
|
||
commands.push( { | ||
name: 'core/toggle-distraction-free-mode', | ||
label: __( 'Toggle spotlight mode' ), | ||
icon: cog, | ||
callback: ( { close } ) => { | ||
toggle( 'core/edit-site', 'focusMode' ); | ||
close(); | ||
}, | ||
} ); | ||
|
||
commands.push( { | ||
name: 'core/toggle-top-toolbar', | ||
label: __( 'Toggle top toolbar' ), | ||
icon: cog, | ||
callback: ( { close } ) => { | ||
toggle( 'core/edit-site', 'fixedToolbar' ); | ||
close(); | ||
}, | ||
} ); | ||
|
||
commands.push( { | ||
name: 'core/toggle-code-editor', | ||
label: __( 'Toggle code editor' ), | ||
icon: code, | ||
callback: ( { close } ) => { | ||
switchEditorMode( editorMode === 'visual' ? 'text' : 'visual' ); | ||
close(); | ||
}, | ||
} ); | ||
|
||
return { | ||
isLoading: false, | ||
commands, | ||
}; | ||
} | ||
|
||
export function useEditModeCommands() { | ||
useCommandLoader( { | ||
name: 'core/edit-site/manipulate-document', | ||
hook: useEditModeCommandLoader, | ||
context: 'site-editor-edit', | ||
} ); | ||
|
||
useCommandLoader( { | ||
name: 'core/edit-site/edit-ui', | ||
hook: useEditUICommandLoader, | ||
} ); | ||
Comment on lines
+215
to
+218
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we using a command loader here instead of regular There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replied in the other PR :) |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an actual bug that made commands run outdated callbacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this the
homeUrl
would get the wrong value (initial value) in the "view site" command.