Skip to content

Commit

Permalink
[Commands]: Add toggle list view command in site editor (#53983)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras authored Aug 28, 2023
1 parent a9252ec commit f2b1fc5
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions packages/edit-site/src/hooks/commands/use-edit-mode-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
blockDefault,
code,
keyboard,
listView,
} from '@wordpress/icons';
import { useCommandLoader } from '@wordpress/commands';
import { decodeEntities } from '@wordpress/html-entities';
Expand Down Expand Up @@ -198,21 +199,27 @@ function useEditUICommands() {
setIsListViewOpened,
switchEditorMode,
} = useDispatch( editSiteStore );
const { canvasMode, editorMode, activeSidebar, showBlockBreadcrumbs } =
useSelect(
( select ) => ( {
canvasMode: unlock( select( editSiteStore ) ).getCanvasMode(),
editorMode: select( editSiteStore ).getEditorMode(),
activeSidebar: select(
interfaceStore
).getActiveComplementaryArea( editSiteStore.name ),
showBlockBreadcrumbs: select( preferencesStore ).get(
'core/edit-site',
'showBlockBreadcrumbs'
),
} ),
[]
);
const {
canvasMode,
editorMode,
activeSidebar,
showBlockBreadcrumbs,
isListViewOpen,
} = useSelect( ( select ) => {
const { isListViewOpened, getEditorMode } = select( editSiteStore );
return {
canvasMode: unlock( select( editSiteStore ) ).getCanvasMode(),
editorMode: getEditorMode(),
activeSidebar: select( interfaceStore ).getActiveComplementaryArea(
editSiteStore.name
),
showBlockBreadcrumbs: select( preferencesStore ).get(
'core/edit-site',
'showBlockBreadcrumbs'
),
isListViewOpen: isListViewOpened(),
};
}, [] );
const { openModal } = useDispatch( interfaceStore );
const { get: getPreference } = useSelect( preferencesStore );
const { set: setPreference, toggle } = useDispatch( preferencesStore );
Expand Down Expand Up @@ -341,6 +348,16 @@ function useEditUICommands() {
},
} );

commands.push( {
name: 'core/toggle-list-view',
label: __( 'Toggle list view' ),
icon: listView,
callback: ( { close } ) => {
setIsListViewOpened( ! isListViewOpen );
close();
},
} );

return {
isLoading: false,
commands,
Expand Down

0 comments on commit f2b1fc5

Please sign in to comment.