Fetch emailPosts for use in template selection modal
MAILPOET-5949
This commit is contained in:
committed by
Oluwaseun Olorunsola
parent
17bda157aa
commit
651e80b8f0
@ -42,7 +42,7 @@ export function SelectTemplateModal( {
|
||||
closeCallback = null,
|
||||
previewContent = '',
|
||||
} ) {
|
||||
const [ templates ] = usePreviewTemplates( previewContent );
|
||||
let [ templates, emailPosts ] = usePreviewTemplates( previewContent );
|
||||
|
||||
const hasTemplates = templates?.length > 0;
|
||||
|
||||
@ -82,6 +82,12 @@ export function SelectTemplateModal( {
|
||||
},
|
||||
];
|
||||
|
||||
let initialCategory = dummyTemplateCategories[ 0 ]; // Show the “Recent” category by default
|
||||
if ( ! emailPosts || emailPosts?.length === 0 ) {
|
||||
emailPosts = [];
|
||||
initialCategory = dummyTemplateCategories[ 1 ]; // user does not recent category, show basic category
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={ __( 'Select a template', 'mailpoet' ) }
|
||||
@ -91,9 +97,9 @@ export function SelectTemplateModal( {
|
||||
isFullScreen
|
||||
>
|
||||
<SelectTemplateBody
|
||||
initialCategory={ dummyTemplateCategories[ 0 ] }
|
||||
initialCategory={ initialCategory }
|
||||
templateCategories={ dummyTemplateCategories }
|
||||
templates={ templates }
|
||||
templates={ [ ...templates, ...emailPosts ] }
|
||||
handleTemplateSelection={ handleTemplateSelection }
|
||||
/>
|
||||
|
||||
|
@ -75,7 +75,7 @@ function TemplateListBox( {
|
||||
minHeight={ 300 }
|
||||
additionalStyles={ [
|
||||
{
|
||||
css: template.template.email_theme_css,
|
||||
css: template.template?.email_theme_css,
|
||||
},
|
||||
] }
|
||||
/>
|
||||
|
@ -1,8 +1,14 @@
|
||||
// import { useMemo } from '@wordpress/element';
|
||||
import { parse } from '@wordpress/blocks';
|
||||
import { BlockInstance } from '@wordpress/blocks/index';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { store as blockEditorStore } from '@wordpress/block-editor';
|
||||
import { storeName, EmailTemplatePreview, TemplatePreview } from '../store';
|
||||
import {
|
||||
storeName,
|
||||
EmailTemplatePreview,
|
||||
TemplatePreview,
|
||||
EmailEditorPostType,
|
||||
} from '../store';
|
||||
|
||||
/**
|
||||
* We need to merge pattern blocks and template blocks for BlockPreview component.
|
||||
@ -34,10 +40,8 @@ function setPostContentInnerBlocks(
|
||||
} );
|
||||
}
|
||||
|
||||
export function usePreviewTemplates(
|
||||
customEmailContent = ''
|
||||
): TemplatePreview[][] {
|
||||
const { templates, patterns } = useSelect( ( select ) => {
|
||||
export function usePreviewTemplates( customEmailContent = '' ) {
|
||||
const { templates, patterns, emailPosts } = useSelect( ( select ) => {
|
||||
const contentBlockId =
|
||||
// @ts-expect-error getBlocksByName is not defined in types
|
||||
select( blockEditorStore ).getBlocksByName(
|
||||
@ -51,6 +55,7 @@ export function usePreviewTemplates(
|
||||
[ 'core/post-content' ],
|
||||
contentBlockId
|
||||
),
|
||||
emailPosts: select( storeName ).getSentEmailEditorPosts(),
|
||||
};
|
||||
}, [] );
|
||||
|
||||
@ -106,5 +111,15 @@ export function usePreviewTemplates(
|
||||
category: 'basic', // TODO: This will be updated once template category is implemented
|
||||
};
|
||||
} ),
|
||||
emailPosts?.map( ( post: EmailEditorPostType ) => {
|
||||
const parsedPostContent = parse( post.content?.raw );
|
||||
return {
|
||||
slug: post.slug,
|
||||
previewContentParsed: parsedPostContent,
|
||||
emailParsed: parsedPostContent,
|
||||
template: post,
|
||||
category: 'recent',
|
||||
};
|
||||
} ),
|
||||
];
|
||||
}
|
||||
|
Reference in New Issue
Block a user