Skip to content

Instantly share code, notes, and snippets.

@jblz
Created June 28, 2017 21:52
Show Gist options
  • Save jblz/09ee002fc78c885b4a8418c87492660e to your computer and use it in GitHub Desktop.
Save jblz/09ee002fc78c885b4a8418c87492660e to your computer and use it in GitHub Desktop.
diff --git a/client/my-sites/preview/main.jsx b/client/my-sites/preview/main.jsx
index 119f0e53db..5327b2bef8 100644
--- a/client/my-sites/preview/main.jsx
+++ b/client/my-sites/preview/main.jsx
@@ -3,6 +3,7 @@
*/
import { connect } from 'react-redux';
import { localize } from 'i18n-calypso';
+import { throttle } from 'lodash';
import React from 'react';
import debugFactory from 'debug';
@@ -12,10 +13,11 @@ import debugFactory from 'debug';
import {
getSelectedSite,
getSelectedSiteId,
+ hasSidebar,
} from 'state/ui/selectors';
import addQueryArgs from 'lib/route/add-query-args';
import { setLayoutFocus } from 'state/ui/layout-focus/actions';
-import { isMobile } from 'lib/viewport';
+import { isWithinBreakpoint } from 'lib/viewport';
import DocumentHead from 'components/data/document-head';
import Main from 'components/main';
@@ -31,9 +33,25 @@ class PreviewMain extends React.Component {
previewUrl: null,
};
+ updateLayout = () => {
+ this.setState( {
+ showingClose: isWithinBreakpoint( '<660px' ),
+ } );
+ }
+
+ throttledUpdateLayout = throttle( this.updateLayout, 100 );
+
componentWillMount() {
+ this.updateLayout();
this.updateUrl();
- this._isMobile = isMobile();
+ }
+
+ componentDidMount() {
+ global.window && global.window.addEventListener( 'resize', this.throttledUpdateLayout );
+ }
+
+ componentWillUnmount() {
+ global.window && global.window.removeEventListener( 'resize', this.throttledUpdateLayout );
}
updateUrl() {
@@ -79,7 +97,7 @@ class PreviewMain extends React.Component {
<Main className="preview">
<DocumentHead title={ translate( 'Site Preview' ) } />
<WebPreviewContent
- showClose={ this._isMobile }
+ showClose={ this.state.showingClose }
onClose={ this.focusSidebar }
previewUrl={ this.state.previewUrl }
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment