@@ -6,6 +6,7 @@ import { useDispatch } from '@wordpress/data';
6
6
import { Modal , SearchControl } from '@wordpress/components' ;
7
7
import { useAsyncList } from '@wordpress/compose' ;
8
8
import {
9
+ BlockContextProvider ,
9
10
store as blockEditorStore ,
10
11
__experimentalBlockPatternsList as BlockPatternsList ,
11
12
} from '@wordpress/block-editor' ;
@@ -38,6 +39,14 @@ export default function PatternSelectionModal( {
38
39
selectBlock ( queryClientIds [ 0 ] ) ;
39
40
}
40
41
} ;
42
+ // When we preview Query Loop blocks we should prefer the current
43
+ // block's postType, which is passed through block context.
44
+ const blockPreviewContext = useMemo (
45
+ ( ) => ( {
46
+ previewPostType : attributes . query . postType ,
47
+ } ) ,
48
+ [ attributes . query . postType ]
49
+ ) ;
41
50
const blockNameForPatterns = useBlockNameForPatterns (
42
51
clientId ,
43
52
attributes
@@ -55,22 +64,24 @@ export default function PatternSelectionModal( {
55
64
closeLabel = { __ ( 'Cancel' ) }
56
65
onRequestClose = { ( ) => setIsPatternSelectionModalOpen ( false ) }
57
66
>
58
- < div className = "block-library-query-pattern__selection-content" >
59
- < div className = "block-library-query-pattern__selection-search" >
60
- < SearchControl
61
- __nextHasNoMarginBottom
62
- onChange = { setSearchValue }
63
- value = { searchValue }
64
- label = { __ ( 'Search for patterns' ) }
65
- placeholder = { __ ( 'Search' ) }
67
+ < BlockContextProvider value = { blockPreviewContext } >
68
+ < div className = "block-library-query-pattern__selection-content" >
69
+ < div className = "block-library-query-pattern__selection-search" >
70
+ < SearchControl
71
+ __nextHasNoMarginBottom
72
+ onChange = { setSearchValue }
73
+ value = { searchValue }
74
+ label = { __ ( 'Search for patterns' ) }
75
+ placeholder = { __ ( 'Search' ) }
76
+ />
77
+ </ div >
78
+ < BlockPatternsList
79
+ blockPatterns = { filteredBlockPatterns }
80
+ shownPatterns = { shownBlockPatterns }
81
+ onClickPattern = { onBlockPatternSelect }
66
82
/>
67
83
</ div >
68
- < BlockPatternsList
69
- blockPatterns = { filteredBlockPatterns }
70
- shownPatterns = { shownBlockPatterns }
71
- onClickPattern = { onBlockPatternSelect }
72
- />
73
- </ div >
84
+ </ BlockContextProvider >
74
85
</ Modal >
75
86
) ;
76
87
}
0 commit comments