Hide recent email categories when swapping a template

[MAILPOET-6425]
This commit is contained in:
Rostislav Wolny
2025-01-16 14:52:42 +01:00
committed by Aschepikov
parent 0a02295c1e
commit 1b565bf430

View File

@ -36,11 +36,18 @@ function SelectTemplateBody( {
hasEmailPosts,
templates,
handleTemplateSelection,
templateSelectMode,
} ) {
const [ selectedCategory, setSelectedCategory ] = useState(
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 ) => {
recordEvent( 'template_select_modal_category_change', { category } );
setSelectedCategory( category );
@ -48,7 +55,7 @@ function SelectTemplateBody( {
useEffect( () => {
setTimeout( () => {
if ( hasEmailPosts ) {
if ( hasEmailPosts && ! hideRecentCategory ) {
setSelectedCategory( TemplateCategories[ 0 ].name );
}
}, 1000 ); // using setTimeout to ensure the template styles are available before block preview
@ -57,7 +64,7 @@ function SelectTemplateBody( {
return (
<div className="block-editor-block-patterns-explorer">
<TemplateCategoriesListSidebar
templateCategories={ TemplateCategories }
templateCategories={ displayCategories }
selectedCategory={ selectedCategory }
onClickCategory={ handleCategorySelection }
/>
@ -142,6 +149,7 @@ export function SelectTemplateModal( {
hasEmailPosts={ hasEmailPosts }
templates={ [ ...templates, ...emailPosts ] }
handleTemplateSelection={ handleTemplateSelection }
templateSelectMode={ templateSelectMode }
/>
<Flex className="email-editor-modal-footer" justify="flex-end">