Fetch postId from the backend and remove reliance on getting the post id from the URL
MAILPOET-6430
This commit is contained in:
committed by
Oluwaseun Olorunsola
parent
a49b978050
commit
6a012a8dd6
1
packages/js/email-editor/src/global.d.ts
vendored
1
packages/js/email-editor/src/global.d.ts
vendored
@ -16,4 +16,5 @@ interface Window {
|
||||
editor_theme: unknown; // Can't import type in global.d.ts. Typed in getEditorTheme() in store/settings.ts
|
||||
};
|
||||
mailpoet_email_editor_current_post_type: string;
|
||||
mailpoet_email_editor_current_post_id: number;
|
||||
}
|
||||
|
@ -7,3 +7,4 @@ export const stylesSidebarId = 'email-editor/editor/styles';
|
||||
|
||||
export const editorCurrentPostType =
|
||||
window.mailpoet_email_editor_current_post_type;
|
||||
export const editorCurrentPostId = window.mailpoet_email_editor_current_post_id;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { mainSidebarDocumentTab } from './constants';
|
||||
import { mainSidebarDocumentTab, editorCurrentPostId } from './constants';
|
||||
import { State } from './types';
|
||||
import {
|
||||
getEditorSettings,
|
||||
@ -12,8 +12,7 @@ import {
|
||||
} from './settings';
|
||||
|
||||
export function getInitialState(): State {
|
||||
const searchParams = new URLSearchParams( window.location.search );
|
||||
const postId = parseInt( searchParams.get( 'post' ), 10 );
|
||||
const postId = editorCurrentPostId;
|
||||
return {
|
||||
inserterSidebar: {
|
||||
isOpened: false,
|
||||
|
@ -317,7 +317,8 @@ class Email_Editor {
|
||||
|
||||
?>
|
||||
<script type="text/javascript"> <?php // phpcs:ignore ?>
|
||||
window.mailpoet_email_editor_current_post_type = <?php echo wp_json_encode( $email_editor_current_post_type ); ?>;
|
||||
window.mailpoet_email_editor_current_post_type = '<?php echo esc_js( $email_editor_current_post_type ); ?>';
|
||||
window.mailpoet_email_editor_current_post_id = <?php echo esc_js( $post->ID ); ?>;
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
Reference in New Issue
Block a user