Skip to content

Commit

Permalink
Gallery block: combine useSelect calls (#57240)
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz authored Dec 20, 2023
1 parent 6bbf33c commit b080c29
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const MOBILE_CONTROL_PROPS_RANGE_CONTROL = Platform.isNative
? { type: 'stepper' }
: {};

const EMPTY_ARRAY = [];

function GalleryEdit( props ) {
const {
setAttributes,
Expand All @@ -97,33 +99,29 @@ function GalleryEdit( props ) {
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );

const { getBlock, getSettings, preferredStyle } = useSelect( ( select ) => {
const settings = select( blockEditorStore ).getSettings();
const preferredStyleVariations =
settings.__experimentalPreferredStyleVariations;
return {
getBlock: select( blockEditorStore ).getBlock,
getSettings: select( blockEditorStore ).getSettings,
preferredStyle: preferredStyleVariations?.value?.[ 'core/image' ],
};
}, [] );

const innerBlockImages = useSelect(
( select ) => {
const innerBlocks =
select( blockEditorStore ).getBlock( clientId )?.innerBlocks ??
[];
return innerBlocks;
},
[ clientId ]
);

const wasBlockJustInserted = useSelect(
const {
getBlock,
getSettings,
preferredStyle,
innerBlockImages,
wasBlockJustInserted,
} = useSelect(
( select ) => {
return select( blockEditorStore ).wasBlockJustInserted(
clientId,
'inserter_menu'
);
const settings = select( blockEditorStore ).getSettings();
const preferredStyleVariations =
settings.__experimentalPreferredStyleVariations;
return {
getBlock: select( blockEditorStore ).getBlock,
getSettings: select( blockEditorStore ).getSettings,
preferredStyle:
preferredStyleVariations?.value?.[ 'core/image' ],
innerBlockImages:
select( blockEditorStore ).getBlock( clientId )
?.innerBlocks ?? EMPTY_ARRAY,
wasBlockJustInserted: select(
blockEditorStore
).wasBlockJustInserted( clientId, 'inserter_menu' ),
};
},
[ clientId ]
);
Expand Down

0 comments on commit b080c29

Please sign in to comment.