Fix header and footer not showing for recent category email post templates

MAILPOET-5949
This commit is contained in:
Oluwaseun Olorunsola
2024-12-06 11:07:38 +01:00
committed by Oluwaseun Olorunsola
parent 4f948dfd65
commit 52a6122e74

View File

@@ -8,6 +8,7 @@ import {
EmailTemplatePreview, EmailTemplatePreview,
TemplatePreview, TemplatePreview,
EmailEditorPostType, EmailEditorPostType,
EmailTheme,
} from '../store'; } from '../store';
/** /**
@@ -42,6 +43,11 @@ function setPostContentInnerBlocks(
const InternalCssThemeCache = {}; const InternalCssThemeCache = {};
type GenerateTemplateCssThemeType = {
emailThemeCss: string;
mailpoetEmailTheme?: EmailTheme;
postTemplateContent?: EmailTemplatePreview;
};
/** /**
* We are reusing the template CSS and mailpoet theme by fetching the template from * We are reusing the template CSS and mailpoet theme by fetching the template from
* the list of email editor available templates. * the list of email editor available templates.
@@ -52,12 +58,13 @@ const InternalCssThemeCache = {};
function generateTemplateCssTheme( function generateTemplateCssTheme(
post: EmailEditorPostType, post: EmailEditorPostType,
allTemplates: TemplatePreview[] = [] allTemplates: TemplatePreview[] = []
) { ): GenerateTemplateCssThemeType {
const contentTemplate = post.template; const contentTemplate = post.template;
const defaultReturnObject = { const defaultReturnObject = {
mailpoet_email_theme: null, mailpoetEmailTheme: null,
email_theme_css: '', emailThemeCss: '',
postTemplateContent: null,
}; };
if ( ! contentTemplate ) { if ( ! contentTemplate ) {
@@ -77,9 +84,10 @@ function generateTemplateCssTheme(
} }
const cssTheme = { const cssTheme = {
mailpoet_email_theme: mailpoetEmailTheme:
postTemplate?.template?.mailpoet_email_theme || null, postTemplate?.template?.mailpoet_email_theme || null,
email_theme_css: postTemplate?.template?.email_theme_css || '', emailThemeCss: postTemplate?.template?.email_theme_css || '',
postTemplateContent: postTemplate?.template,
}; };
InternalCssThemeCache[ contentTemplate ] = cssTheme; InternalCssThemeCache[ contentTemplate ] = cssTheme;
@@ -170,12 +178,23 @@ export function usePreviewTemplates(
const allEmailPosts = useMemo( () => { const allEmailPosts = useMemo( () => {
return emailPosts?.map( ( post: EmailEditorPostType ) => { return emailPosts?.map( ( post: EmailEditorPostType ) => {
const { mailpoetEmailTheme, emailThemeCss, postTemplateContent } =
generateTemplateCssTheme( post, allTemplates );
const parsedPostContent = parse( post.content?.raw ); const parsedPostContent = parse( post.content?.raw );
const cssThemeData = generateTemplateCssTheme( post, allTemplates );
let parsedPostContentWithTemplate = parsedPostContent;
if ( postTemplateContent?.content?.raw ) {
parsedPostContentWithTemplate = setPostContentInnerBlocks(
parse( postTemplateContent?.content?.raw ),
parsedPostContent
);
}
return { return {
id: post.id, id: post.id,
slug: post.slug, slug: post.slug,
previewContentParsed: parsedPostContent, previewContentParsed: parsedPostContentWithTemplate,
emailParsed: parsedPostContent, emailParsed: parsedPostContent,
template: { template: {
...post, ...post,
@@ -184,7 +203,8 @@ export function usePreviewTemplates(
rendered: rendered:
post?.mailpoet_data?.subject || post.title.rendered, // use MailPoet subject as title post?.mailpoet_data?.subject || post.title.rendered, // use MailPoet subject as title
}, },
...cssThemeData, mailpoet_email_theme: mailpoetEmailTheme,
email_theme_css: emailThemeCss,
}, },
category: 'recent', category: 'recent',
type: post.type, type: post.type,