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,
|
closeCallback = null,
|
||||||
previewContent = '',
|
previewContent = '',
|
||||||
} ) {
|
} ) {
|
||||||
const [ templates ] = usePreviewTemplates( previewContent );
|
let [ templates, emailPosts ] = usePreviewTemplates( previewContent );
|
||||||
|
|
||||||
const hasTemplates = templates?.length > 0;
|
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 (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={ __( 'Select a template', 'mailpoet' ) }
|
title={ __( 'Select a template', 'mailpoet' ) }
|
||||||
@ -91,9 +97,9 @@ export function SelectTemplateModal( {
|
|||||||
isFullScreen
|
isFullScreen
|
||||||
>
|
>
|
||||||
<SelectTemplateBody
|
<SelectTemplateBody
|
||||||
initialCategory={ dummyTemplateCategories[ 0 ] }
|
initialCategory={ initialCategory }
|
||||||
templateCategories={ dummyTemplateCategories }
|
templateCategories={ dummyTemplateCategories }
|
||||||
templates={ templates }
|
templates={ [ ...templates, ...emailPosts ] }
|
||||||
handleTemplateSelection={ handleTemplateSelection }
|
handleTemplateSelection={ handleTemplateSelection }
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ function TemplateListBox( {
|
|||||||
minHeight={ 300 }
|
minHeight={ 300 }
|
||||||
additionalStyles={ [
|
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 { parse } from '@wordpress/blocks';
|
||||||
import { BlockInstance } from '@wordpress/blocks/index';
|
import { BlockInstance } from '@wordpress/blocks/index';
|
||||||
import { useSelect } from '@wordpress/data';
|
import { useSelect } from '@wordpress/data';
|
||||||
import { store as blockEditorStore } from '@wordpress/block-editor';
|
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.
|
* We need to merge pattern blocks and template blocks for BlockPreview component.
|
||||||
@ -34,10 +40,8 @@ function setPostContentInnerBlocks(
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePreviewTemplates(
|
export function usePreviewTemplates( customEmailContent = '' ) {
|
||||||
customEmailContent = ''
|
const { templates, patterns, emailPosts } = useSelect( ( select ) => {
|
||||||
): TemplatePreview[][] {
|
|
||||||
const { templates, patterns } = useSelect( ( select ) => {
|
|
||||||
const contentBlockId =
|
const contentBlockId =
|
||||||
// @ts-expect-error getBlocksByName is not defined in types
|
// @ts-expect-error getBlocksByName is not defined in types
|
||||||
select( blockEditorStore ).getBlocksByName(
|
select( blockEditorStore ).getBlocksByName(
|
||||||
@ -51,6 +55,7 @@ export function usePreviewTemplates(
|
|||||||
[ 'core/post-content' ],
|
[ 'core/post-content' ],
|
||||||
contentBlockId
|
contentBlockId
|
||||||
),
|
),
|
||||||
|
emailPosts: select( storeName ).getSentEmailEditorPosts(),
|
||||||
};
|
};
|
||||||
}, [] );
|
}, [] );
|
||||||
|
|
||||||
@ -106,5 +111,15 @@ export function usePreviewTemplates(
|
|||||||
category: 'basic', // TODO: This will be updated once template category is implemented
|
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