-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[RNMobile] Enable reusable block only in WP.com sites #31744
Changes from all commits
f6f9014
5c190b7
1803eba
68434fc
f86d085
0b920ae
d9fe8f9
e157b22
ed8095f
d4c2e1a
233e227
26ea5fb
1f4ad23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,19 +38,18 @@ function useBlockEditorSettings( settings, hasTemplate ) { | |
const { canUserUseUnfilteredHTML, isPostTitleSelected } = select( | ||
editorStore | ||
); | ||
const isWeb = Platform.OS === 'web'; | ||
const { canUser } = select( coreStore ); | ||
|
||
return { | ||
canUseUnfilteredHTML: canUserUseUnfilteredHTML(), | ||
reusableBlocks: select( coreStore ).getEntityRecords( | ||
'postType', | ||
'wp_block', | ||
/** | ||
* Unbounded queries are not supported on native so as a workaround, we set per_page with the maximum value that native version can handle. | ||
* Related issue: https://github.com/wordpress-mobile/gutenberg-mobile/issues/2661 | ||
*/ | ||
{ per_page: Platform.select( { web: -1, native: 100 } ) } | ||
), | ||
reusableBlocks: isWeb | ||
? select( coreStore ).getEntityRecords( | ||
'postType', | ||
'wp_block', | ||
{ per_page: -1 } | ||
) | ||
: [], // Reusable blocks are fetched in the native version of this hook. | ||
Comment on lines
+46
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reusable blocks are fetched in the native version of this hook, so we only fetch them for the web version. |
||
hasUploadPermissions: defaultTo( | ||
canUser( 'create', 'media' ), | ||
true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useMemo } from '@wordpress/element'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useBlockEditorSettings from './use-block-editor-settings.js'; | ||
|
||
function useNativeBlockEditorSettings( settings, hasTemplate ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The purpose of this hook is to add custom code to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the context here. I can see that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah exactly, the main difference between this version and the web is that |
||
const capabilities = settings.capabilities ?? {}; | ||
const editorSettings = useBlockEditorSettings( settings, hasTemplate ); | ||
|
||
const supportReusableBlock = capabilities.reusableBlock === true; | ||
const { reusableBlocks } = useSelect( | ||
( select ) => ( { | ||
reusableBlocks: supportReusableBlock | ||
? select( coreStore ).getEntityRecords( | ||
'postType', | ||
'wp_block', | ||
// Unbounded queries are not supported on native so as a workaround, we set per_page with the maximum value that native version can handle. | ||
// Related issue: https://github.com/wordpress-mobile/gutenberg-mobile/issues/2661 | ||
{ per_page: 100 } | ||
) | ||
: [], | ||
} ), | ||
[ supportReusableBlock ] | ||
); | ||
|
||
return useMemo( | ||
() => ( { | ||
...editorSettings, | ||
__experimentalReusableBlocks: reusableBlocks, | ||
} ), | ||
[ reusableBlocks ] | ||
); | ||
} | ||
|
||
export default useNativeBlockEditorSettings; |
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.
I added the capabilities into the editor settings that are passed to the
EditorProvider
, this is required because we need them when executing theuseNativeBlockEditorSettings
hook.Additionally, to prevent extra re-renders, I decided to memoize the editor settings object.
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.
@fluiddot I was looking around the codebase for some context about what
maxSize
does but I wasn't able to figure it out. Could you please expound a bit on its usage?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.
Is it utilized to define the maximum size of the cache?
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.
Exactly, this parameter controls the size of the cache, here you can check the documentation of the memize package.
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.
There’s a similar logic in this file:
gutenberg/packages/edit-post/src/editor.native.js
Line 39 in a88a3b5
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.
Good good. Thanks for confirming 🙇🏾