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:
committed by
Rostislav Wolný
parent
21dde5362a
commit
02dabf9c01
@ -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';
|
||||
|
16
packages/js/email-editor/src/hooks/use-editor-mode.ts
Normal file
16
packages/js/email-editor/src/hooks/use-editor-mode.ts
Normal 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' ];
|
||||
}
|
Reference in New Issue
Block a user