Cleanup JS code from styles - template association
[MAILPOET-6335]
This commit is contained in:
committed by
Aschepikov
parent
269b55ed08
commit
bc10ae7216
@@ -85,10 +85,7 @@ export function SelectTemplateModal( {
|
||||
}
|
||||
|
||||
void dispatch( storeName ).setTemplateToPost(
|
||||
templateIsPostContent ? postContent.template : template.slug,
|
||||
templateIsPostContent
|
||||
? template?.template?.mailpoet_email_theme || {}
|
||||
: template.template.mailpoet_email_theme ?? {}
|
||||
templateIsPostContent ? postContent.template : template.slug
|
||||
);
|
||||
onSelectCallback();
|
||||
};
|
||||
|
@@ -8,7 +8,6 @@ import {
|
||||
EmailTemplatePreview,
|
||||
TemplatePreview,
|
||||
EmailEditorPostType,
|
||||
EmailTheme,
|
||||
} from '../store';
|
||||
|
||||
/**
|
||||
@@ -41,29 +40,22 @@ function setPostContentInnerBlocks(
|
||||
} );
|
||||
}
|
||||
|
||||
const InternalCssThemeCache = {};
|
||||
const InternalTemplateCache = {};
|
||||
|
||||
type GenerateTemplateCssThemeType = {
|
||||
emailThemeCss: string;
|
||||
mailpoetEmailTheme?: EmailTheme;
|
||||
postTemplateContent?: EmailTemplatePreview;
|
||||
};
|
||||
/**
|
||||
* We are reusing the template CSS and mailpoet theme by fetching the template from
|
||||
* the list of email editor available templates.
|
||||
* Note: This function may need an update when https://mailpoet.atlassian.net/browse/MAILPOET-6335 is merged
|
||||
* @param post
|
||||
* @param allTemplates
|
||||
*/
|
||||
function generateTemplateCssTheme(
|
||||
function generateTemplateContent(
|
||||
post: EmailEditorPostType,
|
||||
allTemplates: TemplatePreview[] = []
|
||||
): GenerateTemplateCssThemeType {
|
||||
const contentTemplate = post.template;
|
||||
|
||||
const defaultReturnObject = {
|
||||
mailpoetEmailTheme: null,
|
||||
emailThemeCss: '',
|
||||
postTemplateContent: null,
|
||||
};
|
||||
|
||||
@@ -71,8 +63,8 @@ function generateTemplateCssTheme(
|
||||
return defaultReturnObject;
|
||||
}
|
||||
|
||||
if ( InternalCssThemeCache[ contentTemplate ] ) {
|
||||
return InternalCssThemeCache[ contentTemplate ];
|
||||
if ( InternalTemplateCache[ contentTemplate ] ) {
|
||||
return InternalTemplateCache[ contentTemplate ];
|
||||
}
|
||||
|
||||
const postTemplate = allTemplates.find(
|
||||
@@ -83,16 +75,13 @@ function generateTemplateCssTheme(
|
||||
return defaultReturnObject;
|
||||
}
|
||||
|
||||
const cssTheme = {
|
||||
mailpoetEmailTheme:
|
||||
postTemplate?.template?.mailpoet_email_theme || null,
|
||||
emailThemeCss: postTemplate?.template?.email_theme_css || '',
|
||||
const templateContent = {
|
||||
postTemplateContent: postTemplate?.template,
|
||||
};
|
||||
|
||||
InternalCssThemeCache[ contentTemplate ] = cssTheme;
|
||||
InternalTemplateCache[ contentTemplate ] = templateContent;
|
||||
|
||||
return cssTheme;
|
||||
return templateContent;
|
||||
}
|
||||
|
||||
export function usePreviewTemplates(
|
||||
@@ -178,8 +167,10 @@ export function usePreviewTemplates(
|
||||
|
||||
const allEmailPosts = useMemo( () => {
|
||||
return emailPosts?.map( ( post: EmailEditorPostType ) => {
|
||||
const { mailpoetEmailTheme, emailThemeCss, postTemplateContent } =
|
||||
generateTemplateCssTheme( post, allTemplates );
|
||||
const { postTemplateContent } = generateTemplateContent(
|
||||
post,
|
||||
allTemplates
|
||||
);
|
||||
const parsedPostContent = parse( post.content?.raw );
|
||||
|
||||
let parsedPostContentWithTemplate = parsedPostContent;
|
||||
@@ -203,8 +194,6 @@ export function usePreviewTemplates(
|
||||
rendered:
|
||||
post?.mailpoet_data?.subject || post.title.rendered, // use MailPoet subject as title
|
||||
},
|
||||
mailpoet_email_theme: mailpoetEmailTheme,
|
||||
email_theme_css: emailThemeCss,
|
||||
},
|
||||
category: 'recent',
|
||||
type: post.type,
|
||||
|
@@ -11,7 +11,7 @@ import { __, sprintf } from '@wordpress/i18n';
|
||||
import { apiFetch } from '@wordpress/data-controls';
|
||||
import wpApiFetch from '@wordpress/api-fetch';
|
||||
import { storeName, mainSidebarDocumentTab } from './constants';
|
||||
import { SendingPreviewStatus, State, Feature, EmailTheme } from './types';
|
||||
import { SendingPreviewStatus, State, Feature } from './types';
|
||||
import { addQueryArgs } from '@wordpress/url';
|
||||
import {
|
||||
// @ts-expect-error No types for __unstableSerializeAndClean
|
||||
@@ -127,16 +127,13 @@ export function* updateEmailMailPoetProperty( name: string, value: string ) {
|
||||
}
|
||||
|
||||
export const setTemplateToPost =
|
||||
( templateSlug, emailTheme: EmailTheme ) =>
|
||||
( templateSlug ) =>
|
||||
async ( { registry } ) => {
|
||||
const postId = registry.select( storeName ).getEmailPostId();
|
||||
registry
|
||||
.dispatch( coreDataStore )
|
||||
.editEntityRecord( 'postType', 'mailpoet_email', postId, {
|
||||
template: templateSlug,
|
||||
meta: {
|
||||
mailpoet_email_theme: emailTheme,
|
||||
},
|
||||
} );
|
||||
};
|
||||
|
||||
|
@@ -206,9 +206,6 @@ export type EmailTemplate = {
|
||||
id: string;
|
||||
slug: string;
|
||||
content: string;
|
||||
email_theme_css: string;
|
||||
mailpoet_email_theme?: EmailTheme;
|
||||
theme: string;
|
||||
title: string;
|
||||
type: string;
|
||||
};
|
||||
|
Reference in New Issue
Block a user