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 Editor: Fix 'useZoomOut' hook conflicts #67033

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 10 additions & 17 deletions packages/block-editor/src/hooks/use-zoom-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,24 @@ import { unlock } from '../lock-unlock';
/**
* A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode.
*
* @param {boolean} zoomOut If we should enter into zoomOut mode or not
* @param {boolean} enabled If we should enter into zoomOut mode or not
*/
export function useZoomOut( zoomOut = true ) {
export function useZoomOut( enabled = true ) {
const { setZoomLevel, resetZoomLevel } = unlock(
useDispatch( blockEditorStore )
);
const { isZoomOut } = unlock( useSelect( blockEditorStore ) );

useEffect( () => {
const isZoomOutOnMount = isZoomOut();

return () => {
if ( isZoomOutOnMount ) {
setZoomLevel( 'auto-scaled' );
} else {
resetZoomLevel();
}
};
}, [] );
if ( ! enabled ) {
return;
}

useEffect( () => {
if ( zoomOut ) {
const isAlreadyInZoomOut = isZoomOut();
if ( ! isAlreadyInZoomOut ) {
setZoomLevel( 'auto-scaled' );
} else {
resetZoomLevel();
}
}, [ zoomOut, setZoomLevel, resetZoomLevel ] );

return () => ! isAlreadyInZoomOut && resetZoomLevel();
}, [ enabled, isZoomOut, resetZoomLevel, setZoomLevel ] );
}
Loading