Skip to content

Commit

Permalink
fix (block examples): the "no blocks found" placeholder appears in ex…
Browse files Browse the repository at this point in the history
…amples generated by the block inserter. fixes gambitph#2405
  • Loading branch information
bfintal committed Dec 26, 2022
1 parent b22c4d1 commit 8813093
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/hooks/use-block-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* External depedencies
*/
import { nth, cloneDeep } from 'lodash'
import { nth, cloneDeep, isEmpty } from 'lodash'

/**
* WordPress dependencies
Expand Down Expand Up @@ -178,12 +178,19 @@ const fixReusableInnerBlocks = blocks => {
} )
}

// The default context if none is found. This can be true when the block is
// being previewed as an example.
const DEFAULT_CONTEXT = {
hasInnerBlocks: true, // This is true so that the "No blocks found" placeholder won't be shown.
}

// Export our hook.
const useBlockContext = ( blockClientId = null ) => {
const blockProps = useBlockEditContext()
const clientId = blockClientId || blockProps.clientId
return useSelect( select => {
return select( 'stackable/block-context' ).getBlockContext( clientId )
const blockContext = select( 'stackable/block-context' ).getBlockContext( clientId )
return ! isEmpty( blockContext ) ? blockContext : DEFAULT_CONTEXT
} )
}

Expand Down

0 comments on commit 8813093

Please sign in to comment.