Skip to content

Commit

Permalink
Set initial scale and fix typo in constant name
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Jan 21, 2021
1 parent 79cd40d commit 08e2d0f
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { get, castArray, debounce, noop } from 'lodash';
import { get, castArray, debounce } from 'lodash';
import classnames from 'classnames';

/**
Expand Down Expand Up @@ -112,20 +112,23 @@ const BlockLayoutPreview = ( {

// Scroll the preview to the top when the blocks change.
useEffect( () => {
const templatePreivew = document.querySelector( '.template-selector-preview' );
if ( ! templatePreivew ) {
const templatePreview = document.querySelector( '.template-selector-preview' );
if ( ! templatePreview ) {
return;
}

// scroll to top when blocks changes.
templatePreivew.scrollTop = 0;
templatePreview.scrollTop = 0;
}, [ recomputeBlockListKey ] );

// Handling windows resize event.
useEffect( () => {
const refreshPreview = debounce( rescale, DEBOUNCE_TIMEOUT );
window.addEventListener( 'resize', refreshPreview );

// Call once initially to ensure layouts are set to the correct scale at the outset.
rescale();

return () => {
window.removeEventListener( 'resize', refreshPreview );
};
Expand Down

0 comments on commit 08e2d0f

Please sign in to comment.