Skip to content

Commit

Permalink
Add: Ability to use creation patterns for other post types besides page
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Jun 17, 2022
1 parent 8d6b3d1 commit 9e4c481
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions packages/edit-post/src/components/start-page-options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ import { store as editPostStore } from '../../store';

function PatternSelection( { onChoosePattern } ) {
const { blockPatterns } = useSelect( ( select ) => {
const { __experimentalGetPatternsByBlockTypes } =
select( blockEditorStore );
const { __experimentalGetPatternsByBlockTypes } = select(
blockEditorStore
);
const { getCurrentPostType } = select( editorStore );
const postType = getCurrentPostType();
return {
blockPatterns:
__experimentalGetPatternsByBlockTypes( 'core/post-content' ),
blockPatterns: ( postType === 'page'
? __experimentalGetPatternsByBlockTypes( 'core/post-content' )
: []
).concat(
__experimentalGetPatternsByBlockTypes(
`core/post-content/${ postType }`
)
),
};
}, [] );
const shownBlockPatterns = useAsyncList( blockPatterns );
Expand Down Expand Up @@ -55,23 +64,29 @@ export default function StartPageOptions() {
if ( modalState !== START_PAGE_MODAL_STATES.INITIAL ) {
return false;
}
const { __experimentalGetPatternsByBlockTypes } =
select( blockEditorStore );
const { __experimentalGetPatternsByBlockTypes } = select(
blockEditorStore
);
const {
getCurrentPostType,
getEditedPostContent,
isEditedPostSaveable,
} = select( editorStore );
const { isEditingTemplate, isFeatureActive } =
select( editPostStore );
const { isEditingTemplate, isFeatureActive } = select(
editPostStore
);
const postType = getCurrentPostType();
return (
getCurrentPostType() === 'page' &&
! isEditedPostSaveable() &&
'' === getEditedPostContent() &&
! isEditingTemplate() &&
! isFeatureActive( 'welcomeGuide' ) &&
__experimentalGetPatternsByBlockTypes( 'core/post-content' )
.length >= 1
( ( postType === 'page' &&
__experimentalGetPatternsByBlockTypes( 'core/post-content' )
.length >= 1 ) ||
__experimentalGetPatternsByBlockTypes(
`core/post-content/${ postType }`
).length >= 1 )
);
},
[ modalState ]
Expand Down

0 comments on commit 9e4c481

Please sign in to comment.