Commit ff8e2dc7 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] handle properly timeout with manual force atlas pausing

Now the timeout for pause won't trigger if user quickly presses
stop/start FA.
parent 3db0957e
......@@ -78,10 +78,10 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
-- ref to track automatic FA pausing
-- If user pauses FA before auto is triggered, clear the timeoutId
-- TODO: mFAPauseRef needs to be set higher up the tree
--mFAPauseRef <- R.useRef Nothing
mFAPauseRef <- R.useRef Nothing
--R.useEffect $ handleForceAtlasPause props.sigmaRef localControls.pauseForceAtlas mFAPauseRef
R.useEffect' $ Sigmax.handleForceAtlas2Pause props.sigmaRef localControls.pauseForceAtlas $ get1 localControls.showEdges
R.useEffect' $ Sigmax.handleForceAtlas2Pause props.sigmaRef localControls.pauseForceAtlas (get1 localControls.showEdges) mFAPauseRef
R.useEffectOnce' $ do
timeoutId <- setTimeout 2000 $ do
......@@ -91,7 +91,8 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
setToggled $ const false
else
pure unit
--R.setRef mFAPauseRef $ Just timeoutId
R.setRef mFAPauseRef Nothing
R.setRef mFAPauseRef $ Just timeoutId
pure unit
pure $ case getShowControls props of
......
......@@ -16,6 +16,7 @@ import Data.Traversable (traverse_)
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested((/\))
import Effect (Effect)
import Effect.Timer (TimeoutId, clearTimeout)
import FFI.Simple (delay)
import Gargantext.Hooks.Sigmax.Sigma as Sigma
import Gargantext.Hooks.Sigmax.Types (Graph(..))
......@@ -282,8 +283,8 @@ useForceAtlas2Eff sigma settings = effect
-- | pausing can be done not only via buttons but also from the initial
-- | setTimer.
--handleForceAtlasPause sigmaRef (toggled /\ setToggled) mFAPauseRef = do
handleForceAtlas2Pause :: R.Ref Sigma -> R.State Boolean -> Boolean -> Effect Unit
handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) showEdges = do
handleForceAtlas2Pause :: R.Ref Sigma -> R.State Boolean -> Boolean -> R.Ref (Maybe TimeoutId) -> Effect Unit
handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) showEdges mFAPauseRef = do
let sigma = R.readRef sigmaRef
dependOnSigma sigma "[handleForceAtlas2Pause] sigma: Nothing" $ \s -> do
--log2 "[handleForceAtlas2Pause] mSigma: Just " s
......@@ -295,6 +296,9 @@ handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) showEdges = do
-- hide edges during forceAtlas rendering, this prevents flickering
Sigma.restartForceAtlas2 s
setEdges s false
case R.readRef mFAPauseRef of
Nothing -> pure unit
Just timeoutId -> clearTimeout timeoutId
Tuple false true -> do
-- restore edges state
Sigma.stopForceAtlas2 s
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment