Skip to content

Commit

Permalink
Make sure the mobile warning notice only runs when images are added t…
Browse files Browse the repository at this point in the history
…o a new gallery block (#36326)

Co-authored-by: Glen Davies <glen.davies@a8c.com>
  • Loading branch information
2 people authored and andrewserong committed Nov 10, 2021
1 parent 00b7a54 commit 369a056
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function GalleryEdit( props ) {
shortCodeTransforms,
sizeSlug,
} = attributes;
useMobileWarning();

const {
__unstableMarkNextChangeAsNotPersistent,
replaceInnerBlocks,
Expand Down Expand Up @@ -139,6 +139,8 @@ function GalleryEdit( props ) {

const newImages = useGetNewImages( images, imageData );

useMobileWarning( newImages );

useEffect( () => {
newImages?.forEach( ( newImage ) => {
updateBlockAttributes( newImage.clientId, {
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/gallery/use-mobile-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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 ) => {
const { isFeatureActive } = select( interfaceStore );
return isFeatureActive( 'core/edit-post', 'mobileGalleryWarning' );
}, [] );

if ( ! isMobileWarningActive ) {
if ( ! isMobileWarningActive || ! newImages ) {
return;
}

Expand Down

0 comments on commit 369a056

Please sign in to comment.