Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. diff --git a/client/my-sites/preview/main.jsx b/client/my-sites/preview/main.jsx
  2. index 119f0e53db..5327b2bef8 100644
  3. --- a/client/my-sites/preview/main.jsx
  4. +++ b/client/my-sites/preview/main.jsx
  5. @@ -3,6 +3,7 @@
  6. */
  7. import { connect } from 'react-redux';
  8. import { localize } from 'i18n-calypso';
  9. +import { throttle } from 'lodash';
  10. import React from 'react';
  11. import debugFactory from 'debug';
  12.  
  13. @@ -12,10 +13,11 @@ import debugFactory from 'debug';
  14. import {
  15. getSelectedSite,
  16. getSelectedSiteId,
  17. + hasSidebar,
  18. } from 'state/ui/selectors';
  19. import addQueryArgs from 'lib/route/add-query-args';
  20. import { setLayoutFocus } from 'state/ui/layout-focus/actions';
  21. -import { isMobile } from 'lib/viewport';
  22. +import { isWithinBreakpoint } from 'lib/viewport';
  23.  
  24. import DocumentHead from 'components/data/document-head';
  25. import Main from 'components/main';
  26. @@ -31,9 +33,25 @@ class PreviewMain extends React.Component {
  27. previewUrl: null,
  28. };
  29.  
  30. + updateLayout = () => {
  31. + this.setState( {
  32. + showingClose: isWithinBreakpoint( '<660px' ),
  33. + } );
  34. + }
  35. +
  36. + throttledUpdateLayout = throttle( this.updateLayout, 100 );
  37. +
  38. componentWillMount() {
  39. + this.updateLayout();
  40. this.updateUrl();
  41. - this._isMobile = isMobile();
  42. + }
  43. +
  44. + componentDidMount() {
  45. + global.window && global.window.addEventListener( 'resize', this.throttledUpdateLayout );
  46. + }
  47. +
  48. + componentWillUnmount() {
  49. + global.window && global.window.removeEventListener( 'resize', this.throttledUpdateLayout );
  50. }
  51.  
  52. updateUrl() {
  53. @@ -79,7 +97,7 @@ class PreviewMain extends React.Component {
  54. <Main className="preview">
  55. <DocumentHead title={ translate( 'Site Preview' ) } />
  56. <WebPreviewContent
  57. - showClose={ this._isMobile }
  58. + showClose={ this.state.showingClose }
  59. onClose={ this.focusSidebar }
  60. previewUrl={ this.state.previewUrl }
  61. />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement