From 82014fe670540a8c4880a468780485fa9cdbcc10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arno=C5=A1t=20Pleskot?= Date: Sun, 9 Jul 2023 12:07:12 +0200 Subject: [PATCH] chore: comments and variable renaming --- src/components/App.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 9316a83e5..3b15d5639 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -7667,13 +7667,12 @@ class App extends React.Component { cursorButton === prevState.cursorButton; // If the state hasn't changed and scrollConstraints didn't just get defined, return null - if ( - !scrollConstraints || - (stateUnchanged && (prevState.scrollConstraints || !scrollConstraints)) - ) { + if (!scrollConstraints || (stateUnchanged && prevState.scrollConstraints)) { return null; } + console.log("fired"); + // Calculate the maximum possible zoom based on the viewport and scrollable area sizes const scrollableWidth = scrollConstraints.width; const scrollableHeight = scrollConstraints.height; @@ -7707,6 +7706,10 @@ class App extends React.Component { const constrainedScrollCenterY = scrollConstraints.y + (scrollableHeight - height / zoom.value) / -2; + // We're using a `switch(true)` construction here to handle a set of conditions + // that can't be easily grouped into a regular switch statement. + // Each case represents a unique combination of cursorButton state and + // whether or not we should adjust for a centered view (constrained area is smaller than viewport). switch (true) { case cursorButton === "down" && shouldAdjustForCenteredView: // case when cursor button is down and we should adjust for centered view @@ -7761,11 +7764,11 @@ class App extends React.Component { constrainedScrollY = Math.min(maxScrollY, Math.max(scrollY, minScrollY)); // Check if the new state differs from the old state - const stateChanged = + // and if the state has changed, update the state and return the new state + const isStateChanged = constrainedScrollX !== scrollX || constrainedScrollY !== scrollY; - // If the state has changed, update the state and return the new state - if (stateChanged) { + if (isStateChanged) { const constrainedState = { scrollX: constrainedScrollX, scrollY: constrainedScrollY,