From be810661cc2f175fc1c34d57fef34e6f33d67196 Mon Sep 17 00:00:00 2001 From: Jeremy Yip Date: Thu, 17 Sep 2020 10:32:19 -0700 Subject: [PATCH] Update title in the core data store --- .../header/document-actions/index.js | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/header/document-actions/index.js b/packages/edit-site/src/components/header/document-actions/index.js index 02f8de9fbbfb9e..e07f571c49d06a 100644 --- a/packages/edit-site/src/components/header/document-actions/index.js +++ b/packages/edit-site/src/components/header/document-actions/index.js @@ -12,7 +12,7 @@ import { __experimentalGetBlockLabel as getBlockLabel, getBlockType, } from '@wordpress/blocks'; -import { useSelect } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; import { DOWN } from '@wordpress/keycodes'; function useSecondaryText() { @@ -46,9 +46,20 @@ export default function DocumentActions( { documentTitle } ) { const { page } = useSelect( ( select ) => { const { getPage } = select( 'core/edit-site' ); - return { page: getPage() }; + const { getEntityRecord } = select( 'core' ); + const _page = getPage(); + return { + page: getEntityRecord( 'postType', 'page', _page?.context?.postId ), + }; } ); + const { editEntityRecord } = useDispatch( 'core' ); + const editTitle = ( title ) => { + editEntityRecord( 'postType', 'page', page.id, { + title, + } ); + }; + return (
{ + const REGEXP_NEWLINES = /[\r\n]+/g; + const title = event.target.value.replace( + REGEXP_NEWLINES, + ' ' + ); + + editTitle( title ); + } } />
) }