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

Minor command tweaks #58148

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
84 changes: 77 additions & 7 deletions packages/edit-post/src/hooks/commands/use-common-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
drawerRight,
blockDefault,
keyboard,
desktop,
fullscreen,
listView,
external,
formatListBullets,
Expand Down Expand Up @@ -39,13 +39,17 @@ export default function useCommonCommands() {
editorMode,
activeSidebar,
isListViewOpen,
isFullscreen,
isPublishSidebarEnabled,
showBlockBreadcrumbs,
isDistractionFree,
isTopToolbar,
isFocusMode,
} = useSelect( ( select ) => {
const { get } = select( preferencesStore );
const { getEditorMode } = select( editPostStore );
const { isListViewOpened } = select( editorStore );

return {
activeSidebar: select( interfaceStore ).getActiveComplementaryArea(
editPostStore.name
Expand All @@ -56,6 +60,9 @@ export default function useCommonCommands() {
select( editorStore ).isPublishSidebarEnabled(),
showBlockBreadcrumbs: get( 'core', 'showBlockBreadcrumbs' ),
isDistractionFree: get( 'core', 'distractionFree' ),
isFocusMode: get( 'core', 'focusMode' ),
isTopToolbar: get( 'core', 'fixedToolbar' ),
isFullscreen: get( 'core/edit-post', 'fullscreenMode' ),
};
}, [] );
const { toggle } = useDispatch( preferencesStore );
Expand Down Expand Up @@ -94,7 +101,9 @@ export default function useCommonCommands() {

useCommand( {
name: 'core/toggle-distraction-free',
label: __( 'Toggle distraction free' ),
label: isDistractionFree
? __( 'Exit Distraction Free' )
: __( 'Enter Distraction Free ' ),
callback: ( { close } ) => {
toggleDistractionFree();
close();
Expand All @@ -103,30 +112,71 @@ export default function useCommonCommands() {

useCommand( {
name: 'core/toggle-spotlight-mode',
label: __( 'Toggle spotlight mode' ),
label: __( 'Toggle spotlight' ),
callback: ( { close } ) => {
toggle( 'core', 'focusMode' );
close();
createInfoNotice(
isFocusMode ? __( 'Spotlight off.' ) : __( 'Spotlight on.' ),
{
id: 'core/edit-post/toggle-spotlight-mode/notice',
type: 'snackbar',
actions: [
{
label: __( 'Undo' ),
onClick: () => {
toggle( 'core', 'focusMode' );
},
},
],
}
);
},
} );

useCommand( {
name: 'core/toggle-fullscreen-mode',
label: __( 'Toggle fullscreen mode' ),
icon: desktop,
label: isFullscreen
? __( 'Exit fullscreen' )
: __( 'Enter fullscreen' ),
icon: fullscreen,
callback: ( { close } ) => {
toggle( 'core/edit-post', 'fullscreenMode' );
close();
createInfoNotice(
isFullscreen ? __( 'Fullscreen off.' ) : __( 'Fullscreen on.' ),
{
id: 'core/edit-post/toggle-fullscreen-mode/notice',
type: 'snackbar',
actions: [
{
label: __( 'Undo' ),
onClick: () => {
toggle( 'core/edit-post', 'fullscreenMode' );
},
},
],
}
);
},
} );

useCommand( {
name: 'core/toggle-list-view',
label: __( 'Toggle list view' ),
label: isListViewOpen
? __( 'Close List View' )
: __( 'Open List View' ),
icon: listView,
callback: ( { close } ) => {
setIsListViewOpened( ! isListViewOpen );
close();
createInfoNotice(
isListViewOpen ? __( 'List View off.' ) : __( 'List View on.' ),
{
id: 'core/edit-post/toggle-list-view/notice',
type: 'snackbar',
}
);
},
} );

Expand All @@ -139,12 +189,32 @@ export default function useCommonCommands() {
toggleDistractionFree();
}
close();
createInfoNotice(
isTopToolbar
? __( 'Top toolbar off.' )
: __( 'Top toolbar on.' ),
{
id: 'core/edit-post/toggle-top-toolbar/notice',
type: 'snackbar',
actions: [
{
label: __( 'Undo' ),
onClick: () => {
toggle( 'core', 'fixedToolbar' );
},
},
],
}
);
},
} );

useCommand( {
name: 'core/toggle-code-editor',
label: __( 'Toggle code editor' ),
label:
editorMode === 'visual'
? __( 'Open code editor' )
: __( 'Exit code editor' ),
Copy link
Member Author

Choose a reason for hiding this comment

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

We use "close" in other commands, but the existing control for the code editor is "Exit" — so we're using that here to maintain that consistency.

icon: code,
callback: ( { close } ) => {
switchEditorMode( editorMode === 'visual' ? 'text' : 'visual' );
Expand Down
10 changes: 10 additions & 0 deletions packages/edit-post/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,16 @@ export const toggleDistractionFree =
{
id: 'core/edit-post/distraction-free-mode/notice',
type: 'snackbar',
actions: [
{
label: __( 'Undo' ),
onClick: () => {
registry
.dispatch( preferencesStore )
.toggle( 'core', 'distractionFree' );
},
},
],
}
);
} );
Expand Down
53 changes: 50 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 @@ -216,6 +216,8 @@ function useEditUICommands() {
showBlockBreadcrumbs,
isListViewOpen,
isDistractionFree,
isTopToolbar,
isFocusMode,
} = useSelect( ( select ) => {
const { get } = select( preferencesStore );
const { getEditorMode } = select( editSiteStore );
Expand All @@ -229,6 +231,8 @@ function useEditUICommands() {
showBlockBreadcrumbs: get( 'core', 'showBlockBreadcrumbs' ),
isListViewOpen: isListViewOpened(),
isDistractionFree: get( 'core', 'distractionFree' ),
isFocusMode: get( 'core', 'focusMode' ),
isTopToolbar: get( 'core', 'fixedToolbar' ),
};
}, [] );
const { openModal } = useDispatch( interfaceStore );
Expand Down Expand Up @@ -271,16 +275,33 @@ function useEditUICommands() {

commands.push( {
name: 'core/toggle-spotlight-mode',
label: __( 'Toggle spotlight mode' ),
label: __( 'Toggle spotlight' ),
callback: ( { close } ) => {
toggle( 'core', 'focusMode' );
close();
createInfoNotice(
isFocusMode ? __( 'Spotlight off.' ) : __( 'Spotlight on.' ),
{
id: 'core/edit-site/toggle-spotlight-mode/notice',
type: 'snackbar',
actions: [
{
label: __( 'Undo' ),
onClick: () => {
toggle( 'core', 'focusMode' );
},
},
],
}
);
},
} );

commands.push( {
name: 'core/toggle-distraction-free',
label: __( 'Toggle distraction free' ),
label: isDistractionFree
? __( 'Exit Distraction Free' )
: __( 'Enter Distraction Free ' ),
callback: ( { close } ) => {
toggleDistractionFree();
close();
Expand All @@ -296,6 +317,23 @@ function useEditUICommands() {
toggleDistractionFree();
}
close();
createInfoNotice(
isTopToolbar
? __( 'Top toolbar off.' )
: __( 'Top toolbar on.' ),
{
id: 'core/edit-site/toggle-top-toolbar/notice',
type: 'snackbar',
actions: [
{
label: __( 'Undo' ),
onClick: () => {
toggle( 'core', 'fixedToolbar' );
},
},
],
}
);
},
} );

Expand Down Expand Up @@ -350,11 +388,20 @@ function useEditUICommands() {

commands.push( {
name: 'core/toggle-list-view',
label: __( 'Toggle list view' ),
label: isListViewOpen
? __( 'Close List View' )
: __( 'Open List View' ),
icon: listView,
callback: ( { close } ) => {
setIsListViewOpened( ! isListViewOpen );
close();
createInfoNotice(
isListViewOpen ? __( 'List View off.' ) : __( 'List View on.' ),
{
id: 'core/edit-site/toggle-list-view/notice',
type: 'snackbar',
}
);
},
} );

Expand Down
10 changes: 10 additions & 0 deletions packages/edit-site/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,16 @@ export const toggleDistractionFree =
{
id: 'core/edit-site/distraction-free-mode/notice',
type: 'snackbar',
actions: [
{
label: __( 'Undo' ),
onClick: () => {
registry
.dispatch( preferencesStore )
.toggle( 'core', 'distractionFree' );
},
},
],
}
);
} );
Expand Down