From c6497f31a28def66b8096ad41565b3f7e9c708bf Mon Sep 17 00:00:00 2001
From: arturo <alting@hotmail.fr>
Date: Fri, 10 Sep 2021 16:41:05 +0200
Subject: [PATCH] [subtree] Fold subtree node by default

* #308 (2): resolve re-render issue
---
 .../Forest/Tree/Node/Action/Move.purs         | 64 +++++++++++++------
 .../Forest/Tree/Node/Tools/SubTree.purs       |  2 +-
 2 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/src/Gargantext/Components/Forest/Tree/Node/Action/Move.purs b/src/Gargantext/Components/Forest/Tree/Node/Action/Move.purs
index da55c9b4..3694baed 100644
--- a/src/Gargantext/Components/Forest/Tree/Node/Action/Move.purs
+++ b/src/Gargantext/Components/Forest/Tree/Node/Action/Move.purs
@@ -1,11 +1,14 @@
-module Gargantext.Components.Forest.Tree.Node.Action.Move where
+module Gargantext.Components.Forest.Tree.Node.Action.Move
+  ( moveNodeReq
+  , moveNode
+  ) where
 
 import Data.Either (Either)
 import Data.Maybe (Maybe(..))
 import Effect.Aff (Aff)
 import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
 import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel)
-import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (subTreeView, SubTreeParamsIn)
+import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (SubTreeParamsIn, subTreeView)
 import Gargantext.Config.REST (RESTError)
 import Gargantext.Prelude
 import Gargantext.Routes (SessionRoute(..))
@@ -30,22 +33,47 @@ moveNodeCpt = here.component "moveNode" cpt
   where
     cpt { boxes, dispatch, id, nodeType, session, subTreeParams } _ = do
       action :: T.Box Action <- T.useBox (MoveNode {params: Nothing})
-      action' <- T.useLive T.unequal action
-
-      let button = case action' of
-              MoveNode { params } -> case params of
-                Just val -> submitButton (MoveNode {params: Just val}) dispatch
-                Nothing -> H.div {} []
-              _                   -> H.div {} []
 
       pure $
 
-        panel [ subTreeView { action
-                            , boxes
-                            , dispatch
-                            , id
-                            , nodeType
-                            , session
-                            , subTreeParams
-                            } []
-            ] button
+        moveNode' { action
+            , boxes
+            , dispatch
+            , id
+            , nodeType
+            , session
+            , subTreeParams
+            } []
+
+type Props =
+  ( action :: T.Box Action
+  | SubTreeParamsIn
+  )
+
+-- @XXX re-render issue -> clone component
+moveNode' :: R2.Component Props
+moveNode' = R.createElement moveNodeCpt'
+moveNodeCpt' :: R.Component Props
+moveNodeCpt' = here.component "foo" cpt where
+  cpt { boxes, dispatch, id, nodeType, session, subTreeParams, action } _ = do
+
+    action' <- T.useLive T.unequal action
+
+    let button = case action' of
+            MoveNode { params } -> case params of
+              Just val -> submitButton (MoveNode {params: Just val}) dispatch
+              Nothing -> H.div {} []
+            _                   -> H.div {} []
+
+    pure $
+
+      panel
+      [ subTreeView { action
+                      , boxes
+                      , dispatch
+                      , id
+                      , nodeType
+                      , session
+                      , subTreeParams
+                      } []
+      ] button
diff --git a/src/Gargantext/Components/Forest/Tree/Node/Tools/SubTree.purs b/src/Gargantext/Components/Forest/Tree/Node/Tools/SubTree.purs
index 1f28cf5d..49e1e04e 100644
--- a/src/Gargantext/Components/Forest/Tree/Node/Tools/SubTree.purs
+++ b/src/Gargantext/Components/Forest/Tree/Node/Tools/SubTree.purs
@@ -44,7 +44,7 @@ type SubTreeParamsProps =
   )
 
 subTreeView :: R2.Component SubTreeParamsProps
-subTreeView = R.createElement subTreeViewCpt
+subTreeView = R.createElement $ R.memo' subTreeViewCpt
 subTreeViewCpt :: R.Component SubTreeParamsProps
 subTreeViewCpt = here.component "subTreeView" cpt
   where
-- 
2.21.0