Add functionality for fetching global styles from server

[MAILPOET-6335]
This commit is contained in:
Rostislav Wolny
2024-12-09 16:00:30 +01:00
committed by Aschepikov
parent 708969954a
commit f906cd686f
3 changed files with 26 additions and 0 deletions

View File

@ -24,6 +24,9 @@ export function getInitialState(): State {
postId,
editorSettings: getEditorSettings(),
theme: getEditorTheme(),
styles: {
globalStylesPostId: 153, // Todo - fetch from DB
},
autosaveInterval: 60,
cdnUrl: getCdnUrl(),
isPremiumPluginActive: isPremiumPluginActive(),

View File

@ -7,6 +7,7 @@ import { serialize } from '@wordpress/blocks';
import { BlockInstance } from '@wordpress/blocks/index';
import { storeName } from './constants';
import { State, Feature, EmailTemplate, EmailEditorPostType } from './types';
import { Post } from '@wordpress/core-data/build-types/entity-types/post';
export const isFeatureActive = createRegistrySelector(
( select ) =>
@ -220,6 +221,21 @@ export const getCurrentTemplate = createRegistrySelector( ( select ) => () => {
return getEditedPostTemplate();
} );
export const getGlobalEmailStylesPost = createRegistrySelector(
( select ) => () => {
const postId = select( storeName ).getGlobalStylesPostId();
if ( postId ) {
return select( coreDataStore ).getEditedEntityRecord(
'postType',
'wp_global_styles',
postId
) as unknown as Post;
}
return getEditedPostTemplate();
}
);
/**
* Retrieves the email templates.
*/
@ -292,6 +308,10 @@ export function getTheme( state: State ): State[ 'theme' ] {
return state.theme;
}
export function getGlobalStylesPostId( state: State ): number | null {
return state.styles.globalStylesPostId;
}
export function getUrls( state: State ): State[ 'urls' ] {
return state.urls;
}

View File

@ -179,6 +179,9 @@ export type State = {
postId: number;
editorSettings: EmailEditorSettings;
theme: EmailTheme;
styles: {
globalStylesPostId: number | null;
};
autosaveInterval: number;
cdnUrl: string;
urls: EmailEditorUrls;