Move.purs 1.8 KB
Newer Older
1
module Gargantext.Components.Forest.Tree.Node.Action.Move where
2 3

import Data.Maybe (Maybe(..))
4
import Effect.Aff (Aff)
5 6
import Reactix as R
import Reactix.DOM.HTML as H
7
import Toestand as T
8

9 10
import Gargantext.Prelude

11
import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
12
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel)
13
import Gargantext.Components.Forest.Tree.Node.Tools.SubTree (subTreeView, SubTreeParamsIn)
14 15
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, put_)
16
import Gargantext.Types as GT
17
import Gargantext.Utils.Reactix as R2
18

19 20
here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Move"
21

22 23
moveNodeReq :: Session -> GT.ID -> GT.ID -> Aff (Array GT.ID)
moveNodeReq session fromId toId =
24 25
  put_ session $ NodeAPI GT.Node (Just fromId) ("move/" <> show toId)

26 27
moveNode :: R2.Component SubTreeParamsIn
moveNode = R.createElement moveNodeCpt
28
moveNodeCpt :: R.Component SubTreeParamsIn
29
moveNodeCpt = here.component "moveNode" cpt
30
  where
31
    cpt { dispatch, handed, id, nodeType, session, subTreeParams } _ = do
32 33
      action :: T.Box Action <- T.useBox (MoveNode {params: Nothing})
      action' <- T.useLive T.unequal action
34

35 36
      let button = case action' of
              MoveNode { params } -> case params of
37 38 39
                Just val -> submitButton (MoveNode {params: Just val}) dispatch
                Nothing -> H.div {} []
              _                   -> H.div {} []
40

41 42
      pure $ panel [ subTreeView { action
                                 , dispatch
43
                                 , handed
44 45 46 47
                                 , id
                                 , nodeType
                                 , session
                                 , subTreeParams
48
                                 } []
49
              ] button