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
Use Gutenberg store #226
Merged
Merged
Use Gutenberg store #226
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
595bd4f
Connect App and AppContainer to the gutenberg store as well
Tug ab76265
Replace local store with gutenberg store
Tug d95d6a2
Cleanup and optimize blocks change
Tug 4812743
Mock react-native-recyclerview-list
Tug f4c3bc0
Intialize refresh to false by default
Tug 3f3787c
Add jest-preset-default as dependency to ensure it's loaded when gute…
Tug 7ce9175
Do not overwrite dataSource but instead keep it in sync using the ui …
Tug afe12a2
More reliable way to update focus, do not share object references wit…
Tug 0357cfe
Refactor App and AppContainer to not depend on the gb-mobile store an…
Tug 4ad24dc
Remove old store
Tug ec35d6a
Fix merging blocks using the new store
Tug 34bc0b9
Add back the test that modifies the store
Tug 0c614ea
Make a shallow copy of blocks instead of deep copy
Tug d7ea973
Fix updating dataSource from blocks props
Tug File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Submodule gutenberg
updated
21 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule react-native-aztec
updated
2 files
+4 −4 | android/build.gradle | |
+1 −1 | android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecText.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,136 @@ | ||
/** @flow | ||
* @format */ | ||
|
||
import { connect } from 'react-redux'; | ||
import { | ||
updateBlockAttributes, | ||
focusBlockAction, | ||
moveBlockUpAction, | ||
moveBlockDownAction, | ||
deleteBlockAction, | ||
createBlockAction, | ||
parseBlocksAction, | ||
serializeToNativeAction, | ||
mergeBlocksAction, | ||
} from '../store/actions'; | ||
import MainApp from './MainApp'; | ||
import React from 'react'; | ||
import { parse, serialize } from '@wordpress/blocks'; | ||
import { withDispatch, withSelect } from '@wordpress/data'; | ||
import { compose } from '@wordpress/compose'; | ||
import RNReactNativeGutenbergBridge from 'react-native-gutenberg-bridge'; | ||
import type { BlockType } from '../store/types'; | ||
|
||
const mapStateToProps = ( state ) => ( { | ||
...state, | ||
} ); | ||
|
||
const mapDispatchToProps = ( dispatch, ownProps ) => { | ||
return { | ||
...ownProps, | ||
onChange: ( clientId, attributes ) => { | ||
dispatch( updateBlockAttributes( clientId, attributes ) ); | ||
}, | ||
focusBlockAction: ( clientId ) => { | ||
dispatch( focusBlockAction( clientId ) ); | ||
}, | ||
moveBlockUpAction: ( clientId ) => { | ||
dispatch( moveBlockUpAction( clientId ) ); | ||
}, | ||
moveBlockDownAction: ( clientId ) => { | ||
dispatch( moveBlockDownAction( clientId ) ); | ||
}, | ||
deleteBlockAction: ( clientId ) => { | ||
dispatch( deleteBlockAction( clientId ) ); | ||
}, | ||
createBlockAction: ( clientId, block, clientIdAbove ) => { | ||
dispatch( createBlockAction( clientId, block, clientIdAbove ) ); | ||
}, | ||
parseBlocksAction: ( html ) => { | ||
dispatch( parseBlocksAction( html ) ); | ||
}, | ||
serializeToNativeAction: () => { | ||
dispatch( serializeToNativeAction() ); | ||
}, | ||
mergeBlocksAction: ( blockOneClientId, blockTwoClientId, block ) => { | ||
dispatch( mergeBlocksAction( blockOneClientId, blockTwoClientId, block ) ); | ||
}, | ||
}; | ||
type PropsType = { | ||
rootClientId: string, | ||
isBlockSelected: string => boolean, | ||
selectedBlockIndex: number, | ||
blocks: Array<BlockType>, | ||
onInsertBlock: ( BlockType, number, string ) => mixed, | ||
onMerge: ( string, string ) => mixed, | ||
onMoveDown: string => mixed, | ||
onMoveUp: string => mixed, | ||
onRemove: string => mixed, | ||
onResetBlocks: Array<BlockType> => mixed, | ||
onSelect: string => mixed, | ||
onAttributesUpdate: ( string, mixed ) => mixed, | ||
initialHtml: string, | ||
}; | ||
|
||
const AppContainer = connect( mapStateToProps, mapDispatchToProps )( MainApp ); | ||
export default AppContainer; | ||
class AppContainer extends React.Component<PropsType> { | ||
constructor( props: PropsType ) { | ||
super( props ); | ||
|
||
this.parseBlocksAction( props.initialHtml ); | ||
} | ||
|
||
onChange = ( clientId, attributes ) => { | ||
this.props.onAttributesUpdate( clientId, attributes ); | ||
}; | ||
|
||
focusBlockAction = ( clientId ) => { | ||
this.props.onSelect( clientId ); | ||
}; | ||
|
||
moveBlockUpAction = ( clientId ) => { | ||
this.props.onMoveUp( clientId ); | ||
}; | ||
|
||
moveBlockDownAction = ( clientId ) => { | ||
this.props.onMoveDown( clientId ); | ||
}; | ||
|
||
deleteBlockAction = ( clientId ) => { | ||
this.props.onRemove( clientId ); | ||
}; | ||
|
||
createBlockAction = ( clientId, block ) => { | ||
this.props.onInsertBlock( block, this.props.selectedBlockIndex + 1, this.props.rootClientId ); | ||
}; | ||
|
||
parseBlocksAction = ( html = '' ) => { | ||
const parsed = parse( html ); | ||
this.props.onResetBlocks( parsed ); | ||
}; | ||
|
||
serializeToNativeAction = () => { | ||
const html = serialize( this.props.blocks ); | ||
RNReactNativeGutenbergBridge.provideToNative_Html( html ); | ||
}; | ||
|
||
mergeBlocksAction = ( blockOneClientId, blockTwoClientId ) => { | ||
this.props.onMerge( blockOneClientId, blockTwoClientId ); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<MainApp | ||
blocks={ this.props.blocks } | ||
onChange={ this.onChange } | ||
focusBlockAction={ this.focusBlockAction } | ||
moveBlockUpAction={ this.moveBlockUpAction } | ||
moveBlockDownAction={ this.moveBlockDownAction } | ||
deleteBlockAction={ this.deleteBlockAction } | ||
createBlockAction={ this.createBlockAction } | ||
parseBlocksAction={ this.parseBlocksAction } | ||
serializeToNativeAction={ this.serializeToNativeAction } | ||
mergeBlocksAction={ this.mergeBlocksAction } | ||
isBlockSelected={ this.props.isBlockSelected } | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select ) => { | ||
const { | ||
getBlockIndex, | ||
getBlocks, | ||
getSelectedBlockClientId, | ||
isBlockSelected, | ||
} = select( 'core/editor' ); | ||
const selectedBlockClientId = getSelectedBlockClientId(); | ||
|
||
return { | ||
isBlockSelected, | ||
selectedBlockIndex: getBlockIndex( selectedBlockClientId ), | ||
blocks: getBlocks(), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch ) => { | ||
const { | ||
clearSelectedBlock, | ||
insertBlock, | ||
mergeBlocks, | ||
moveBlocksDown, | ||
moveBlocksUp, | ||
removeBlock, | ||
resetBlocks, | ||
selectBlock, | ||
updateBlockAttributes, | ||
} = dispatch( 'core/editor' ); | ||
|
||
return { | ||
clearSelectedBlock, | ||
onInsertBlock: insertBlock, | ||
onMerge: mergeBlocks, | ||
onMoveDown: moveBlocksDown, | ||
onMoveUp: moveBlocksUp, | ||
onRemove: removeBlock, | ||
onResetBlocks: resetBlocks, | ||
onSelect: ( clientId ) => { | ||
clearSelectedBlock(); | ||
selectBlock( clientId ); | ||
}, | ||
onAttributesUpdate: updateBlockAttributes, | ||
}; | ||
} ), | ||
] )( AppContainer ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this state isn't used anywhere afaics.