Skip to content

Commit

Permalink
[Block Editor - Inserter]: preload media categories empty check - cli…
Browse files Browse the repository at this point in the history
…ent side (#47503)

* [Block Editor - Inserter]: preload media categories empty client side

* show media tab if `enableOpenverseMediaCategory` setting is `true`
  • Loading branch information
ntsekouras committed Feb 21, 2023
1 parent 9fa1e90 commit 42bba6e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 38 deletions.
23 changes: 0 additions & 23 deletions lib/compat/wordpress-6.2/edit-form-blocks.php

This file was deleted.

1 change: 0 additions & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.2/block-template-utils.php';
require __DIR__ . '/compat/wordpress-6.2/get-global-styles-and-settings.php';
require __DIR__ . '/compat/wordpress-6.2/default-filters.php';
require __DIR__ . '/compat/wordpress-6.2/edit-form-blocks.php';
require __DIR__ . '/compat/wordpress-6.2/site-editor.php';
require __DIR__ . '/compat/wordpress-6.2/block-editor.php';
require __DIR__ . '/compat/wordpress-6.2/block-editor-settings.php';
Expand Down
34 changes: 20 additions & 14 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,33 @@ function InserterMenu(
insertionIndex: __experimentalInsertionIndex,
shouldFocusBlock,
} );
const { showPatterns, inserterItems } = useSelect(
( select ) => {
const { __experimentalGetAllowedPatterns, getInserterItems } =
select( blockEditorStore );
return {
showPatterns: !! __experimentalGetAllowedPatterns(
destinationRootClientId
).length,
inserterItems: getInserterItems( destinationRootClientId ),
};
},
[ destinationRootClientId ]
);
const { showPatterns, inserterItems, enableOpenverseMediaCategory } =
useSelect(
( select ) => {
const {
__experimentalGetAllowedPatterns,
getInserterItems,
getSettings,
} = select( blockEditorStore );
return {
showPatterns: !! __experimentalGetAllowedPatterns(
destinationRootClientId
).length,
inserterItems: getInserterItems( destinationRootClientId ),
enableOpenverseMediaCategory:
getSettings().enableOpenverseMediaCategory,
};
},
[ destinationRootClientId ]
);
const hasReusableBlocks = useMemo( () => {
return inserterItems.some(
( { category } ) => category === 'reusable'
);
}, [ inserterItems ] );

const mediaCategories = useMediaCategories( destinationRootClientId );
const showMedia = !! mediaCategories.length;
const showMedia = !! mediaCategories.length || enableOpenverseMediaCategory;

const onInsert = useCallback(
( blocks, meta, shouldForceFocusBlock ) => {
Expand Down

0 comments on commit 42bba6e

Please sign in to comment.