]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] Change window resize handler to switch to/from mobile layout as soon as...
authorThibG <thib@sitedethib.com>
Sun, 25 Aug 2019 13:48:50 +0000 (15:48 +0200)
committerThibaut Girka <thib@sitedethib.com>
Thu, 29 Aug 2019 15:32:22 +0000 (17:32 +0200)
Port bd4099d976b52f7ec00e00b23cfe6e2766ff1e4d to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
app/javascript/flavours/glitch/features/ui/index.js

index dbfaf1220d4070930a1e90824ca52a2ee6f0f388..33625581df2ff2e82d256b656efeae816e5a743a 100644 (file)
@@ -138,14 +138,24 @@ class SwitchingColumnsArea extends React.PureComponent {
     window.removeEventListener('resize', this.handleResize);
   }
 
-  handleResize = debounce(() => {
+  handleLayoutChange = debounce(() => {
     // The cached heights are no longer accurate, invalidate
     this.props.onLayoutChange();
-
-    this.setState({ mobile: isMobile(window.innerWidth, this.props.layout) });
   }, 500, {
     trailing: true,
-  });
+  })
+
+  handleResize = () => {
+    const mobile = isMobile(window.innerWidth, this.props.layout);
+
+    if (mobile !== this.state.mobile) {
+      this.handleLayoutChange.cancel();
+      this.props.onLayoutChange();
+      this.setState({ mobile });
+    } else {
+      this.handleLayoutChange();
+    }
+  }
 
   setRef = c => {
     this.node = c.getWrappedInstance();