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,
|
||||
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">
|
||||
|
Reference in New Issue
Block a user