Skip to content

Commit

Permalink
Send contentInfo information when updating HTML. (#23115)
Browse files Browse the repository at this point in the history
* Send contentInfo information when updating HTML.

* Rename content info names.

* Fix lint issues.

* Change to getGlobalCount to count blocks.

* Remove unused method.

* Remove unused variable.

* Add comment to method.
  • Loading branch information
SergioEstevao committed Jun 16, 2020
1 parent 7433677 commit c996134
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/editor/src/components/provider/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import RNReactNativeGutenbergBridge, {
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { count as wordCount } from '@wordpress/wordcount';
import {
parse,
serialize,
Expand Down Expand Up @@ -181,10 +182,20 @@ class NativeEditorProvider extends Component {
const hasChanges =
title !== this.post.title.raw || html !== this.post.content.raw;

// Variable to store the content structure metrics.
const contentInfo = {};
contentInfo.characterCount = wordCount(
html,
'characters_including_spaces'
);
contentInfo.wordCount = wordCount( html, 'words' );
contentInfo.paragraphCount = this.props.paragraphCount;
contentInfo.blockCount = this.props.blockCount;
RNReactNativeGutenbergBridge.provideToNative_Html(
html,
title,
hasChanges
hasChanges,
contentInfo
);

if ( hasChanges ) {
Expand Down Expand Up @@ -228,7 +239,7 @@ class NativeEditorProvider extends Component {
}

export default compose( [
withSelect( ( select, { rootClientId } ) => {
withSelect( ( select ) => {
const {
__unstableIsEditorReady: isEditorReady,
getEditorBlocks,
Expand All @@ -238,9 +249,9 @@ export default compose( [
const { getEditorMode } = select( 'core/edit-post' );

const {
getBlockCount,
getBlockIndex,
getSelectedBlockClientId,
getGlobalBlockCount,
} = select( 'core/block-editor' );

const selectedBlockClientId = getSelectedBlockClientId();
Expand All @@ -251,7 +262,8 @@ export default compose( [
title: getEditedPostAttribute( 'title' ),
getEditedPostContent,
selectedBlockIndex: getBlockIndex( selectedBlockClientId ),
blockCount: getBlockCount( rootClientId ),
blockCount: getGlobalBlockCount(),
paragraphCount: getGlobalBlockCount( 'core/paragraph' ),
};
} ),
withDispatch( ( dispatch ) => {
Expand Down

0 comments on commit c996134

Please sign in to comment.