Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions assets/js/src/components/DesignPackNotice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { useSelect } from '@wordpress/data';
import { Icon, closeSmall } from '@wordpress/icons';
import { useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

const logo = (
<svg
Expand All @@ -20,17 +21,41 @@ const logo = (
</svg>
);

// WP < 6.8 id; 6.8+ shares 'inserter-notice' with other inserter snackbars.
const BLOCK_PATTERN_INSERTED_NOTICE = 'block-pattern-inserted-notice';
const INSERTER_NOTICE = 'inserter-notice';

const isPatternInsertedNotice = ( notice ) => {
if ( notice.id === BLOCK_PATTERN_INSERTED_NOTICE ) {
return true;
}

if ( notice.id !== INSERTER_NOTICE || typeof notice.content !== 'string' ) {
return false;
}

// Core's wording before and after its rename (6.9 → 7.1).
return [
/* translators: %s: block pattern title. */
__( 'Block pattern "%s" inserted.' ),
/* translators: %s: block pattern title. */
__( 'Pattern "%s" inserted.' ),
].some( ( template ) => {
const [ before, after = '' ] = template.split( /%(?:\d+\$)?s/ );

return (
notice.content.startsWith( before ) &&
notice.content.endsWith( after )
);
} );
};

export default () => {
const [ dismissed, setDismissed ] = useState( false );
const [ noticeTriggered, setNoticeTriggered ] = useState( false );

const patternInserted = useSelect(
( select ) =>
select( 'core/notices' )
.getNotices()
.filter( ( n ) => n.id === BLOCK_PATTERN_INSERTED_NOTICE )
.length > 0
const patternInserted = useSelect( ( select ) =>
select( 'core/notices' ).getNotices().some( isPatternInsertedNotice )
);

useEffect( () => {
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading