Skip to content

Commit

Permalink
Fix the condition for the modal to choose the initial template pattern (
Browse files Browse the repository at this point in the history
#49954)

* Fix the condition for the modal to choose the initial template pattern
* Fix ESLint warning
* Fix typo in the variable name
  • Loading branch information
Mamaduka authored Apr 20, 2023
1 parent 0ff9e08 commit b2b8e50
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/edit-site/src/components/start-template-options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function useFallbackTemplateContent( slug, isCustom = false ) {
ignore_empty: true,
} ),
} ).then( ( { content } ) => setTemplateContent( content.raw ) );
}, [ slug ] );
}, [ isCustom, slug ] );
return templateContent;
}

Expand Down Expand Up @@ -147,28 +147,28 @@ export default function StartTemplateOptions() {
const [ modalState, setModalState ] = useState(
START_TEMPLATE_MODAL_STATES.INITIAL
);
const { shouldOpenModel, slug, isCustom, postType } = useSelect(
const { shouldOpenModal, slug, isCustom, postType } = useSelect(
( select ) => {
const { getEditedPostType, getEditedPostId } =
select( editSiteStore );
const _postType = getEditedPostType();
const postId = getEditedPostId();
const {
__experimentalGetDirtyEntityRecords,
getEditedEntityRecord,
} = select( coreStore );
const { getEditedEntityRecord, hasEditsForEntityRecord } =
select( coreStore );
const templateRecord = getEditedEntityRecord(
'postType',
_postType,
postId
);

const hasDirtyEntityRecords =
__experimentalGetDirtyEntityRecords().length > 0;
const hasEdits = hasEditsForEntityRecord(
'postType',
_postType,
postId
);

return {
shouldOpenModel:
! hasDirtyEntityRecords &&
shouldOpenModal:
! hasEdits &&
'' === templateRecord.content &&
'wp_template' === _postType &&
! select( preferencesStore ).get(
Expand All @@ -185,7 +185,7 @@ export default function StartTemplateOptions() {

if (
( modalState === START_TEMPLATE_MODAL_STATES.INITIAL &&
! shouldOpenModel ) ||
! shouldOpenModal ) ||
modalState === START_TEMPLATE_MODAL_STATES.CLOSED
) {
return null;
Expand Down

0 comments on commit b2b8e50

Please sign in to comment.