From 9b500f5d8c55bc8dcea0e1026c6705ccd810d6cf Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Fri, 14 Jul 2023 10:31:03 +1000 Subject: [PATCH 1/5] Store and update post status in `dt` object. --- assets/js/gutenberg-plugin.js | 3 +++ assets/js/push.js | 4 +++- includes/push-ui.php | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/assets/js/gutenberg-plugin.js b/assets/js/gutenberg-plugin.js index 6d8306c24..7856bd093 100644 --- a/assets/js/gutenberg-plugin.js +++ b/assets/js/gutenberg-plugin.js @@ -187,8 +187,11 @@ const DistributorPlugin = () => { const post = useSelect( ( select ) => select( 'core/editor' ).getCurrentPost() ); + console.log( post ); // Make the post title available to the top menu. dt.postTitle = post.title; + // Make the post status available to the top menu. + dt.postStatus = post.status; // If we are on a non-supported post status, change what we show if ( diff --git a/assets/js/push.js b/assets/js/push.js index eb26e12db..8c8a51a07 100755 --- a/assets/js/push.js +++ b/assets/js/push.js @@ -401,6 +401,7 @@ jQuery( window ).on( 'load', () => { foundConnections: mustacheData.connections.length, showSearch: 5 < mustacheData.connections.length, postTitle: dt.postTitle, + postStatus: dt.postStatus, } ); @@ -409,6 +410,7 @@ jQuery( window ).on( 'load', () => { distributorPushWrapper.innerHTML = template( { connections: dtConnections, postTitle: dt.postTitle, + postStatus: dt.postStatus, } ); } @@ -516,7 +518,7 @@ jQuery( window ).on( 'load', () => { data.postStatus = null !== asDraftInput && asDraftInput.checked ? 'draft' - : postStatusInput.value; + : dt.postStatus; const xhr = dt.usexhr ? { withCredentials: true } : false; diff --git a/includes/push-ui.php b/includes/push-ui.php index b58a5ad7e..d883425ed 100644 --- a/includes/push-ui.php +++ b/includes/push-ui.php @@ -414,6 +414,7 @@ function enqueue_scripts( $hook ) { 'loadConnectionsNonce' => wp_create_nonce( 'dt-load-connections' ), 'postId' => (int) get_the_ID(), 'postTitle' => get_the_title(), + 'postStatus' => get_post_status(), 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), /** From 5a76939cbec409a3dbbe8b68df95e64648eb02f0 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Fri, 14 Jul 2023 11:31:26 +1000 Subject: [PATCH 2/5] Remove unused `dt-post-status` input. --- assets/js/push.js | 2 -- templates/show-connections-amp.php | 1 - templates/show-connections.php | 1 - 3 files changed, 4 deletions(-) diff --git a/assets/js/push.js b/assets/js/push.js index 8c8a51a07..96290d47e 100755 --- a/assets/js/push.js +++ b/assets/js/push.js @@ -50,7 +50,6 @@ jQuery( window ).on( 'load', () => { let selectAllConnections = ''; let selectNoConnections = ''; let connectionsSearchInput = ''; - let postStatusInput = ''; let asDraftInput = ''; let errorDetails = ''; @@ -91,7 +90,6 @@ jQuery( window ).on( 'load', () => { connectionsSearchInput = document.getElementById( 'dt-connection-search' ); - postStatusInput = document.getElementById( 'dt-post-status' ); asDraftInput = document.getElementById( 'dt-as-draft' ); errorDetails = document.querySelector( '.dt-error ul.details' ); diff --git a/templates/show-connections-amp.php b/templates/show-connections-amp.php index 98cdda683..a50833b5d 100644 --- a/templates/show-connections-amp.php +++ b/templates/show-connections-amp.php @@ -55,7 +55,6 @@ class="add-connection{{#syndicated}} syndicated{{/syndicated}}"
- post_status ) ? true : false; /** diff --git a/templates/show-connections.php b/templates/show-connections.php index cbc74ae68..cdfeb7c2f 100644 --- a/templates/show-connections.php +++ b/templates/show-connections.php @@ -53,7 +53,6 @@ class="add-connection<# if ( ! _.isEmpty( connections[ key ]['syndicated'] ) ) {
- post_status ) ? true : false; /** From 81c278897e1df8d37c2120beff9dfa6e4e1b3438 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Fri, 14 Jul 2023 11:32:12 +1000 Subject: [PATCH 3/5] Remove console.log. --- assets/js/gutenberg-plugin.js | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/js/gutenberg-plugin.js b/assets/js/gutenberg-plugin.js index 7856bd093..afb78d684 100644 --- a/assets/js/gutenberg-plugin.js +++ b/assets/js/gutenberg-plugin.js @@ -187,7 +187,6 @@ const DistributorPlugin = () => { const post = useSelect( ( select ) => select( 'core/editor' ).getCurrentPost() ); - console.log( post ); // Make the post title available to the top menu. dt.postTitle = post.title; // Make the post status available to the top menu. From 785614c09e6e6e4af7dabbe0d83d21790e8123a2 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Fri, 14 Jul 2023 11:32:36 +1000 Subject: [PATCH 4/5] Tidy up comments. --- assets/js/gutenberg-plugin.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assets/js/gutenberg-plugin.js b/assets/js/gutenberg-plugin.js index afb78d684..2fe6800c2 100644 --- a/assets/js/gutenberg-plugin.js +++ b/assets/js/gutenberg-plugin.js @@ -187,9 +187,8 @@ const DistributorPlugin = () => { const post = useSelect( ( select ) => select( 'core/editor' ).getCurrentPost() ); - // Make the post title available to the top menu. + // Make the post title and status available to the top menu. dt.postTitle = post.title; - // Make the post status available to the top menu. dt.postStatus = post.status; // If we are on a non-supported post status, change what we show From 278d12656207634c2f7b378f35b4eaf5332d82b4 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Fri, 14 Jul 2023 11:40:03 +1000 Subject: [PATCH 5/5] Remove uneeded data when rendering template. --- assets/js/push.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/assets/js/push.js b/assets/js/push.js index 96290d47e..4846c8185 100755 --- a/assets/js/push.js +++ b/assets/js/push.js @@ -399,7 +399,6 @@ jQuery( window ).on( 'load', () => { foundConnections: mustacheData.connections.length, showSearch: 5 < mustacheData.connections.length, postTitle: dt.postTitle, - postStatus: dt.postStatus, } ); @@ -408,7 +407,6 @@ jQuery( window ).on( 'load', () => { distributorPushWrapper.innerHTML = template( { connections: dtConnections, postTitle: dt.postTitle, - postStatus: dt.postStatus, } ); }