From 7992786771a6c67716a88d477253c96af1bc30b7 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 9 Nov 2021 09:33:52 +1300 Subject: [PATCH] Make sure the mobile warning notice only runs when images are added to a new gallery block --- packages/block-library/src/gallery/edit.js | 4 +++- packages/block-library/src/gallery/use-mobile-warning.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/gallery/edit.js b/packages/block-library/src/gallery/edit.js index 22ca116c92d13d..e0a25548f00f2e 100644 --- a/packages/block-library/src/gallery/edit.js +++ b/packages/block-library/src/gallery/edit.js @@ -97,7 +97,7 @@ function GalleryEdit( props ) { shortCodeTransforms, sizeSlug, } = attributes; - useMobileWarning(); + const { __unstableMarkNextChangeAsNotPersistent, replaceInnerBlocks, @@ -139,6 +139,8 @@ function GalleryEdit( props ) { const newImages = useGetNewImages( images, imageData ); + useMobileWarning( newImages ); + useEffect( () => { newImages?.forEach( ( newImage ) => { updateBlockAttributes( newImage.clientId, { diff --git a/packages/block-library/src/gallery/use-mobile-warning.js b/packages/block-library/src/gallery/use-mobile-warning.js index cefaa26b9f3a2e..6567d8f73349b7 100644 --- a/packages/block-library/src/gallery/use-mobile-warning.js +++ b/packages/block-library/src/gallery/use-mobile-warning.js @@ -6,7 +6,7 @@ import { useDispatch, useSelect } from '@wordpress/data'; import { store as interfaceStore } from '@wordpress/interface'; import { store as noticesStore } from '@wordpress/notices'; -export default function useMobileWarning() { +export default function useMobileWarning( newImages ) { const { createWarningNotice } = useDispatch( noticesStore ); const { toggleFeature } = useDispatch( interfaceStore ); const isMobileWarningActive = useSelect( ( select ) => { @@ -14,7 +14,7 @@ export default function useMobileWarning() { return isFeatureActive( 'core/edit-post', 'mobileGalleryWarning' ); }, [] ); - if ( ! isMobileWarningActive ) { + if ( ! isMobileWarningActive || ! newImages ) { return; }