Skip to content

Commit

Permalink
Block Library: Cleanup unnecessary notice removal (WordPress#66409)
Browse files Browse the repository at this point in the history
Co-authored-by: tyxla <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: jsnajdr <[email protected]>
  • Loading branch information
4 people authored Oct 24, 2024
1 parent 0faf4c5 commit 62e0e6f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
8 changes: 2 additions & 6 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,11 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
);

// If a user clicks to a link prevent redirection and show a warning.
const { createWarningNotice, removeNotice } = useDispatch( noticeStore );
let noticeId;
const { createWarningNotice } = useDispatch( noticeStore );
const showRedirectionPreventedNotice = ( event ) => {
event.preventDefault();
// Remove previous warning if any, to show one at a time per block.
removeNotice( noticeId );
noticeId = `block-library/core/latest-posts/redirection-prevented/${ instanceId }`;
createWarningNotice( __( 'Links are disabled in the editor.' ), {
id: noticeId,
id: `block-library/core/latest-posts/redirection-prevented/${ instanceId }`,
type: 'snackbar',
} );
};
Expand Down
10 changes: 3 additions & 7 deletions packages/block-library/src/table-of-contents/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ToolbarGroup,
} from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { renderToString, useRef } from '@wordpress/element';
import { renderToString } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useInstanceId } from '@wordpress/compose';
import { store as noticeStore } from '@wordpress/notices';
Expand Down Expand Up @@ -58,15 +58,11 @@ export default function TableOfContentsEdit( {
);

// If a user clicks to a link prevent redirection and show a warning.
const { createWarningNotice, removeNotice } = useDispatch( noticeStore );
const noticeIdRef = useRef();
const { createWarningNotice } = useDispatch( noticeStore );
const showRedirectionPreventedNotice = ( event ) => {
event.preventDefault();
// Remove previous warning if any, to show one at a time per block.
removeNotice( noticeIdRef.current );
noticeIdRef.current = `block-library/core/table-of-contents/redirection-prevented/${ instanceId }`;
createWarningNotice( __( 'Links are disabled in the editor.' ), {
id: noticeIdRef.current,
id: `block-library/core/table-of-contents/redirection-prevented/${ instanceId }`,
type: 'snackbar',
} );
};
Expand Down

0 comments on commit 62e0e6f

Please sign in to comment.