From 29ebfb8b139b8efc3dfe4866da9998374fb32ca1 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Tue, 28 Nov 2023 15:08:02 +0530 Subject: [PATCH 1/2] Add autosave after resize content and generate titles. --- .../gutenberg-plugins/content-resizing-plugin.js | 15 ++++++++++++++- src/js/gutenberg-plugins/post-status-info.js | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/js/gutenberg-plugins/content-resizing-plugin.js b/src/js/gutenberg-plugins/content-resizing-plugin.js index e99c95e60..7753a86d3 100644 --- a/src/js/gutenberg-plugins/content-resizing-plugin.js +++ b/src/js/gutenberg-plugins/content-resizing-plugin.js @@ -222,7 +222,11 @@ const ContentResizingPlugin = () => { * * @param {string} updateWith The content that will be used to replace the selection. */ - function updateContent( updateWith ) { + async function updateContent( updateWith ) { + const isDirty = await select( 'core/editor' ).isEditedPostDirty(); + const postId = select( 'core/editor' ).getCurrentPostId(); + const postType = select( 'core/editor' ).getCurrentPostType(); + dispatch( blockEditorStore ).updateBlockAttributes( selectedBlock.clientId, { @@ -237,6 +241,15 @@ const ContentResizingPlugin = () => { updateWith.length ); resetStates(); + + // If no edited values in post trigger save. + if ( ! isDirty ) { + await dispatch( 'core' ).saveEditedEntityRecord( + 'postType', + postType, + postId + ); + } } // We don't want to use the reszing feature when multiple blocks are selected. diff --git a/src/js/gutenberg-plugins/post-status-info.js b/src/js/gutenberg-plugins/post-status-info.js index 4c9e380f4..5fa351685 100644 --- a/src/js/gutenberg-plugins/post-status-info.js +++ b/src/js/gutenberg-plugins/post-status-info.js @@ -37,6 +37,7 @@ const PostStatusInfo = () => { } const postId = select( 'core/editor' ).getCurrentPostId(); + const postType = select( 'core/editor' ).getCurrentPostType(); const postContent = select( 'core/editor' ).getEditedPostAttribute( 'content' ); const openModal = () => setOpen( true ); @@ -85,11 +86,24 @@ const PostStatusInfo = () => {