Skip to content

Commit

Permalink
[Edit Post]: Add toggle fullscreen mode and list view commands (#52184)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras authored and tellthemachines committed Jul 7, 2023
1 parent df103c2 commit b776600
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions packages/edit-post/src/hooks/commands/use-common-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
drawerRight,
blockDefault,
keyboardClose,
desktop,
listView,
} from '@wordpress/icons';
import { useCommand } from '@wordpress/commands';
import { store as preferencesStore } from '@wordpress/preferences';
Expand All @@ -23,16 +25,24 @@ import { PREFERENCES_MODAL_NAME } from '../../components/preferences-modal';
import { store as editPostStore } from '../../store';

export default function useCommonCommands() {
const { openGeneralSidebar, closeGeneralSidebar, switchEditorMode } =
useDispatch( editPostStore );
const {
openGeneralSidebar,
closeGeneralSidebar,
switchEditorMode,
setIsListViewOpened,
} = useDispatch( editPostStore );
const { openModal } = useDispatch( interfaceStore );
const { editorMode, activeSidebar } = useSelect(
( select ) => ( {
activeSidebar: select( interfaceStore ).getActiveComplementaryArea(
editPostStore.name
),
editorMode: select( editPostStore ).getEditorMode(),
} ),
const { editorMode, activeSidebar, isListViewOpen } = useSelect(
( select ) => {
const { getEditorMode, isListViewOpened } = select( editPostStore );
return {
activeSidebar: select(
interfaceStore
).getActiveComplementaryArea( editPostStore.name ),
editorMode: getEditorMode(),
isListViewOpen: isListViewOpened(),
};
},
[]
);
const { toggle } = useDispatch( preferencesStore );
Expand Down Expand Up @@ -85,6 +95,26 @@ export default function useCommonCommands() {
},
} );

useCommand( {
name: 'core/toggle-fullscreen-mode',
label: __( 'Toggle fullscreen mode' ),
icon: desktop,
callback: ( { close } ) => {
toggle( 'core/edit-post', 'fullscreenMode' );
close();
},
} );

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

useCommand( {
name: 'core/toggle-top-toolbar',
label: __( 'Toggle top toolbar' ),
Expand Down

0 comments on commit b776600

Please sign in to comment.