Hide recent email categories when swapping a template
[MAILPOET-6425]
This commit is contained in:
committed by
Aschepikov
parent
0a02295c1e
commit
1b565bf430
@ -36,11 +36,18 @@ function SelectTemplateBody( {
|
|||||||
hasEmailPosts,
|
hasEmailPosts,
|
||||||
templates,
|
templates,
|
||||||
handleTemplateSelection,
|
handleTemplateSelection,
|
||||||
|
templateSelectMode,
|
||||||
} ) {
|
} ) {
|
||||||
const [ selectedCategory, setSelectedCategory ] = useState(
|
const [ selectedCategory, setSelectedCategory ] = useState(
|
||||||
TemplateCategories[ 1 ].name // Show the “Basic” category by default
|
TemplateCategories[ 1 ].name // Show the “Basic” category by default
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const hideRecentCategory = templateSelectMode === 'swap';
|
||||||
|
|
||||||
|
const displayCategories = TemplateCategories.filter(
|
||||||
|
( { name } ) => name !== 'recent' || ! hideRecentCategory
|
||||||
|
);
|
||||||
|
|
||||||
const handleCategorySelection = ( category: TemplateCategory ) => {
|
const handleCategorySelection = ( category: TemplateCategory ) => {
|
||||||
recordEvent( 'template_select_modal_category_change', { category } );
|
recordEvent( 'template_select_modal_category_change', { category } );
|
||||||
setSelectedCategory( category );
|
setSelectedCategory( category );
|
||||||
@ -48,7 +55,7 @@ function SelectTemplateBody( {
|
|||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
if ( hasEmailPosts ) {
|
if ( hasEmailPosts && ! hideRecentCategory ) {
|
||||||
setSelectedCategory( TemplateCategories[ 0 ].name );
|
setSelectedCategory( TemplateCategories[ 0 ].name );
|
||||||
}
|
}
|
||||||
}, 1000 ); // using setTimeout to ensure the template styles are available before block preview
|
}, 1000 ); // using setTimeout to ensure the template styles are available before block preview
|
||||||
@ -57,7 +64,7 @@ function SelectTemplateBody( {
|
|||||||
return (
|
return (
|
||||||
<div className="block-editor-block-patterns-explorer">
|
<div className="block-editor-block-patterns-explorer">
|
||||||
<TemplateCategoriesListSidebar
|
<TemplateCategoriesListSidebar
|
||||||
templateCategories={ TemplateCategories }
|
templateCategories={ displayCategories }
|
||||||
selectedCategory={ selectedCategory }
|
selectedCategory={ selectedCategory }
|
||||||
onClickCategory={ handleCategorySelection }
|
onClickCategory={ handleCategorySelection }
|
||||||
/>
|
/>
|
||||||
@ -142,6 +149,7 @@ export function SelectTemplateModal( {
|
|||||||
hasEmailPosts={ hasEmailPosts }
|
hasEmailPosts={ hasEmailPosts }
|
||||||
templates={ [ ...templates, ...emailPosts ] }
|
templates={ [ ...templates, ...emailPosts ] }
|
||||||
handleTemplateSelection={ handleTemplateSelection }
|
handleTemplateSelection={ handleTemplateSelection }
|
||||||
|
templateSelectMode={ templateSelectMode }
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Flex className="email-editor-modal-footer" justify="flex-end">
|
<Flex className="email-editor-modal-footer" justify="flex-end">
|
||||||
|
Reference in New Issue
Block a user