Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new empty para block on Enter.KEY #159

Merged
merged 15 commits into from
Oct 16, 2018

Conversation

daniloercoli
Copy link
Contributor

@daniloercoli daniloercoli commented Oct 12, 2018

This PR updates GB hash, and adds the code to insert a new para block after the current focused when enter.key is pressed.

There are few problems at the moment, not strictly related to this PR, explained below:

  • this.props.focusBlockAction( newBlock.clientId ) in block-manager.js is not working fine, the new block is not getting the focus, both if you tap + on the bottom toolbar and both if you press Enter.key in a para/heading block. cc @mzorz
  • There are problems getting the focus on blocks on Android, and consequence of this is that the bottom block management toolbar is not visible, and the index of the current block unknown. consequence of this is that I needed to add a hack to insert the block in the middle of the list atm.

GB side PR is available here: WordPress/gutenberg#10553

// find currently focused block
let focusedItemIndex = this.findDataSourceIndexForFocusedItem();
if ( focusedItemIndex == -1 ) {
// no focus yet? This is a well knwon bug on Android...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a ToDo comment here to fix it instead of leaving the magic number 3 with no other explanation

@daniloercoli
Copy link
Contributor Author

Removed empty lines and added a TODO - Thanks for your review @mzorz !

…g-mobile into try/add-new-empty-block-after-focus-on-enter-key

Resolved conflicts over
#	gutenberg
@@ -139,6 +139,27 @@ export default class BlockManager extends React.Component<PropsType, StateType>
this.state.dataSource.setDirty();
}

insertBlocksAfter( blocks: Array<Object> ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that since we're passing this function to each of the blocks, we can actually specialize it to accept the block clientId and emit an action to add the blocks after this specific clientId. We won't need to rely on which block is selected at that moment. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting...will try that!

Copy link
Contributor

@hypest hypest Oct 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Just to expand a bit, we can make block-manager's insertBlocksAfter accept the clientID but we can still pass a wrapped version down to the block-holder that only needs the blocks parameter.

… to BlockManager together with the blocks list.

No need to find the current focused block since we already have the blockID that started the action.
@@ -49,6 +50,14 @@ export default class BlockHolder extends React.Component<PropsType, StateType> {
return <View />;
}

_insertBlocksAfter( blocks: Array<Object> ) {
Copy link
Contributor

@hypest hypest Oct 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In https://github.com/wordpress-mobile/gutenberg-mobile/pull/159/files#diff-2d50daf729e068ecebcce113d1ce7f9aR270, we pass the insertBlocksAfter method to all the rendered items so, I don't think we need to check whether the prop exists, right?

Then again, I think we don't even need this _insertBlocksAfter here at all as we can construct a wrapped method with just the blocks parameter right there in https://github.com/wordpress-mobile/gutenberg-mobile/pull/159/files#diff-2d50daf729e068ecebcce113d1ce7f9aR270.

For example we can have this in block-manager.js:

insertBlocksAfter={ ( blocks ) =>
	this.insertBlocksAfter.bind( this )( value.item.clientId, blocks )
}

WDYT?

@@ -19,6 +19,7 @@ type PropsType = BlockType & {
onChange: ( clientId: string, attributes: mixed ) => void,
onToolbarButtonPressed: ( button: number, clientId: string ) => void,
onBlockHolderPressed: ( clientId: string ) => void,
insertBlocksAfter: ( clientId: string, blocks: Array<Object> ) => void,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to remove the clientId parameter from the definition here. Essentially, what we will be passing down to the block-holder is a function with the clientId string already "embedded" in it so, we will just call it by passing the new blocks.

Copy link
Contributor

@hypest hypest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @daniloercoli ! Feel free to update to the GB side when that gets merged and merge this one too!

Copy link
Contributor

@mzorz mzorz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work here @daniloercoli !

@daniloercoli
Copy link
Contributor Author

Thanks @hypest and @mzorz for your review!

@daniloercoli daniloercoli merged commit c226162 into master Oct 16, 2018
@daniloercoli daniloercoli deleted the try/add-new-empty-block-after-focus-on-enter-key branch October 16, 2018 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants