Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Library: Cleanup unnecessary notice removal #66409

Merged
merged 1 commit into from
Oct 24, 2024
Merged
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
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
Loading