Fetch postId from the backend and remove reliance on getting the post id from the URL

MAILPOET-6430
This commit is contained in:
Oluwaseun Olorunsola
2025-01-28 23:14:41 +01:00
committed by Oluwaseun Olorunsola
parent a49b978050
commit 6a012a8dd6
4 changed files with 6 additions and 4 deletions

View File

@ -16,4 +16,5 @@ interface Window {
editor_theme: unknown; // Can't import type in global.d.ts. Typed in getEditorTheme() in store/settings.ts 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_type: string;
mailpoet_email_editor_current_post_id: number;
} }

View File

@ -7,3 +7,4 @@ export const stylesSidebarId = 'email-editor/editor/styles';
export const editorCurrentPostType = export const editorCurrentPostType =
window.mailpoet_email_editor_current_post_type; window.mailpoet_email_editor_current_post_type;
export const editorCurrentPostId = window.mailpoet_email_editor_current_post_id;

View File

@ -1,7 +1,7 @@
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { mainSidebarDocumentTab } from './constants'; import { mainSidebarDocumentTab, editorCurrentPostId } from './constants';
import { State } from './types'; import { State } from './types';
import { import {
getEditorSettings, getEditorSettings,
@ -12,8 +12,7 @@ import {
} from './settings'; } from './settings';
export function getInitialState(): State { export function getInitialState(): State {
const searchParams = new URLSearchParams( window.location.search ); const postId = editorCurrentPostId;
const postId = parseInt( searchParams.get( 'post' ), 10 );
return { return {
inserterSidebar: { inserterSidebar: {
isOpened: false, isOpened: false,

View File

@ -317,7 +317,8 @@ class Email_Editor {
?> ?>
<script type="text/javascript"> <?php // phpcs:ignore ?> <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> </script>
<?php <?php
} }