Skip to content

Commit

Permalink
[Site Editor]: Fix multiple templates creation while in the process o…
Browse files Browse the repository at this point in the history
…f creating one
  • Loading branch information
ntsekouras committed Sep 14, 2022
1 parent daece9c commit f020d44
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/edit-site/src/components/add-new-template/new-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
MenuItem,
NavigableMenu,
} from '@wordpress/components';
import { useState } from '@wordpress/element';
import { useState, useRef } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import {
Expand Down Expand Up @@ -86,14 +86,24 @@ export default function NewTemplate( { postType } ) {
setShowCustomGenericTemplateModal,
] = useState( false );
const [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );
const isCreatingTemplate = useRef();

const history = useHistory();
const { saveEntityRecord } = useDispatch( coreStore );
const { createErrorNotice, createSuccessNotice } =
const { createErrorNotice, createSuccessNotice, createInfoNotice } =
useDispatch( noticesStore );
const { setTemplate } = useDispatch( editSiteStore );

async function createTemplate( template, isWPSuggestion = true ) {
if ( isCreatingTemplate.current ) {
return;
}
isCreatingTemplate.current = true;
createInfoNotice(
// translators: displayed right after clicking the menu item to create a new template in site editor.
__( 'Template creation in process.' ),
{ type: 'snackbar' }
);
try {
const { title, description, slug, templatePrefix } = template;
let templateContent = template.content;
Expand Down Expand Up @@ -151,6 +161,8 @@ export default function NewTemplate( { postType } ) {
createErrorNotice( errorMessage, {
type: 'snackbar',
} );
} finally {
isCreatingTemplate.current = false;
}
}

Expand Down

0 comments on commit f020d44

Please sign in to comment.