Add a custom hook to determine whether we are in email or template mode

There are a couple of places where we determine the mode, but we use different approaches.
This commit adds a mechanism for determining the editor mode which can be easily reusable
in the whole app.
[MAILPOET-6336]
This commit is contained in:
Rostislav Wolny
2024-12-02 15:56:02 +01:00
committed by Rostislav Wolný
parent 21dde5362a
commit 02dabf9c01
2 changed files with 17 additions and 0 deletions

View File

@ -4,3 +4,4 @@ export * from './use-validation-notices';
export * from './use-email-styles';
export * from './use-email-css';
export * from './use-preview-templates';
export * from './use-editor-mode';

View File

@ -0,0 +1,16 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
export function useEditorMode() {
const { isEditingTemplate } = useSelect(
( select ) => ( {
isEditingTemplate:
select( editorStore ).getCurrentPostType() === 'wp_template',
} ),
[]
);
return [ isEditingTemplate ? 'template' : 'email' ];
}