From 42bba6ec5dcebed0b99d24297400c5220fde70ca Mon Sep 17 00:00:00 2001 From: Nik Tsekouras Date: Tue, 21 Feb 2023 12:18:25 +0200 Subject: [PATCH] [Block Editor - Inserter]: preload media categories empty check - client side (#47503) * [Block Editor - Inserter]: preload media categories empty client side * show media tab if `enableOpenverseMediaCategory` setting is `true` --- lib/compat/wordpress-6.2/edit-form-blocks.php | 23 ------------- lib/load.php | 1 - .../src/components/inserter/menu.js | 34 +++++++++++-------- 3 files changed, 20 insertions(+), 38 deletions(-) delete mode 100644 lib/compat/wordpress-6.2/edit-form-blocks.php diff --git a/lib/compat/wordpress-6.2/edit-form-blocks.php b/lib/compat/wordpress-6.2/edit-form-blocks.php deleted file mode 100644 index 479ade3f37763..0000000000000 --- a/lib/compat/wordpress-6.2/edit-form-blocks.php +++ /dev/null @@ -1,23 +0,0 @@ - { - 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' @@ -87,7 +93,7 @@ function InserterMenu( }, [ inserterItems ] ); const mediaCategories = useMediaCategories( destinationRootClientId ); - const showMedia = !! mediaCategories.length; + const showMedia = !! mediaCategories.length || enableOpenverseMediaCategory; const onInsert = useCallback( ( blocks, meta, shouldForceFocusBlock ) => {