Commit 8b60a7c0 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[toestand] action with useBox

parent 2ea4d48f
......@@ -58,8 +58,29 @@ setTreeOut (LinkNode {nodeType, params:_}) p = LinkNode {nodeType, params: p}
setTreeOut (SharePublic {params:_}) p = SharePublic {params: p}
setTreeOut a _ = a
instance showShow :: Show Action where
derive instance genericAction :: Generic Action _
instance eqAction :: Eq Action where
eq (AddNode s1 nt1) (AddNode s2 nt2) = (eq s1 s2) && (eq nt1 nt2)
eq (DeleteNode nt1) (DeleteNode nt2) = eq nt1 nt2
eq (RenameNode s1) (RenameNode s2) = eq s1 s2
eq (UpdateNode un1) (UpdateNode un2) = eq un1 un2
eq (DoSearch at1) (DoSearch at2) = eq at1 at2
eq (UploadFile nt1 ft1 s1 _) (UploadFile nt2 ft2 s2 _) = (eq nt1 nt2) && (eq ft1 ft2) && (eq s1 s2)
eq (UploadArbitraryFile s1 _) (UploadArbitraryFile s2 _) = eq s1 s2
eq DownloadNode DownloadNode = true
eq RefreshTree RefreshTree = true
eq ClosePopover ClosePopover = true
eq (ShareTeam s1) (ShareTeam s2) = eq s1 s2
eq (AddContact ac1) (AddContact ac2) = eq ac1 ac2
eq (SharePublic p1) (SharePublic p2) = eq p1 p2
eq (MoveNode p1) (MoveNode p2) = eq p1 p2
eq (MergeNode p1) (MergeNode p2) = eq p1 p2
eq (LinkNode l1) (LinkNode l2) = eq l1 l2
eq NoAction NoAction = true
eq _ _ = false
instance showAction :: Show Action where
show (AddNode _ _ ) = "AddNode"
show (DeleteNode _ ) = "DeleteNode"
show (RenameNode _ ) = "RenameNode"
......
......@@ -8,6 +8,7 @@ import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel)
......@@ -53,11 +54,11 @@ linkNodeCpt :: R.Component SubTreeParamsIn
linkNodeCpt = here.component "linkNode" cpt
where
cpt p@{dispatch, subTreeParams, id, nodeType, session, handed} _ = do
action <- T.useBox (LinkNode { nodeType: Nothing, params: Nothing})
action' <- T.useLive T.unequal action
action@(valAction /\ setAction) :: R.State Action <- R.useState' (LinkNode {nodeType:Nothing,params:Nothing})
let button = case valAction of
LinkNode {params} -> case params of
let button = case action' of
LinkNode { params } -> case params of
Just val -> submitButton (LinkNode {nodeType: Just nodeType, params: Just val}) dispatch
Nothing -> H.div {} []
_ -> H.div {} []
......@@ -65,10 +66,10 @@ linkNodeCpt = here.component "linkNode" cpt
pure $ panel [
subTreeView { action
, dispatch
, handed
, id
, nodeType
, session
, subTreeParams
, handed
}
} []
] button
......@@ -31,7 +31,8 @@ mergeNodeCpt :: R.Component SubTreeParamsIn
mergeNodeCpt = here.component "mergeNode" cpt
where
cpt p@{dispatch, subTreeParams, id, nodeType, session, handed} _ = do
action@(action' /\ _) :: R.State Action <- R.useState' (MergeNode {params:Nothing})
action <- T.useBox (MergeNode { params: Nothing })
action' <- T.useLive T.unequal action
merge <- T.useBox false
options <- T.useBox (Set.singleton GT.MapTerm)
......@@ -45,12 +46,12 @@ mergeNodeCpt = here.component "mergeNode" cpt
pure $ panel
[ subTreeView { action
, dispatch
, handed
, id
, nodeType
, session
, subTreeParams
, handed
}
} []
, H.ul { className:"merge mx-auto list-group"}
([ H.li { className: "list-group-item" }
[ H.h5 { className: "mb-1" } [ H.text "Merge which list?" ]
......
......@@ -9,6 +9,7 @@ import Effect.Aff (Aff)
import Prelude (($))
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Components.Forest.Tree.Node.Action (Action)
import Gargantext.Components.Forest.Tree.Node.Action as Action
......@@ -63,21 +64,22 @@ shareNodeCpt :: R.Component SubTreeParamsIn
shareNodeCpt = here.component "shareNode" cpt
where
cpt p@{dispatch, subTreeParams, id, nodeType, session, handed} _ = do
action@(valAction /\ setAction) :: R.State Action <- R.useState' (Action.SharePublic {params: Nothing})
action <- T.useBox (Action.SharePublic { params: Nothing })
action' <- T.useLive T.unequal action
let button = case valAction of
Action.SharePublic {params} -> case params of
let button = case action' of
Action.SharePublic { params } -> case params of
Just val -> Tools.submitButton (Action.SharePublic {params: Just val}) dispatch
Nothing -> H.div {} []
_ -> H.div {} []
pure $ Tools.panel [ subTreeView { action
, dispatch
, handed
, id
, nodeType
, session
, subTreeParams
, handed
}
} []
] button
......@@ -94,18 +94,18 @@ subTreeViewLoadedCpt = here.component "subTreeViewLoaded" cpt
let pRender = Record.merge { render: subTreeTreeView } p
pure $ H.div {className:"tree"}
[ H.div { className: if handed == GT.RightHanded
then "righthanded"
else "lefthanded"
}
[ subTreeTreeView pRender [] ]
]
[ H.div { className: if handed == GT.RightHanded
then "righthanded"
else "lefthanded"
}
[ subTreeTreeView (CorpusTreeRenderProps pRender) [] ]
]
newtype CorpusTreeRenderProps = CorpusTreeRenderProps
{ render :: R2.NTHooksComponent CorpusTreeRenderProps
{ render :: CorpusTreeRenderProps -> Array R.Element -> R.Element
| CorpusTreeProps }
subTreeTreeView :: R2.NTComponent CorpusTreeRenderProps
subTreeTreeView :: CorpusTreeRenderProps -> Array R.Element -> R.Element
subTreeTreeView = R2.ntCreateElement subTreeTreeViewCpt
subTreeTreeViewCpt :: R2.NTComponent CorpusTreeRenderProps
......@@ -125,7 +125,7 @@ subTreeTreeViewCpt = here.ntComponent "subTreeTreeView" cpt where
E.stopPropagation e
T.modify_ (\a -> setTreeOut a action'') action
children = map (\ctree -> render (CorpusTreeRenderProps (p { tree = ctree })) []) sortedAry
children = (map (\ctree -> render (CorpusTreeRenderProps (p { tree = ctree })) []) sortedAry) :: Array R.Element
pure $ H.div {} $ GT.reverseHanded handed
[ H.div { className: nodeClass validNodeType }
......
......@@ -10,14 +10,20 @@ import Reactix as R
data SubTreeOut = SubTreeOut { in :: GT.ID
, out :: GT.ID
}
derive instance genericSubTreeOut :: Generic SubTreeOut _
instance eqSubTreOut :: Eq SubTreeOut where
eq = genericEq
instance showSubTreeOut :: Show SubTreeOut where
show = genericShow
------------------------------------------------------------------------
data SubTreeParams = SubTreeParams { showtypes :: Array GT.NodeType
, valitypes :: Array GT.NodeType
}
derive instance eqSubTreeParams :: Eq SubTreeParams
derive instance genericSubTreeParams :: Generic SubTreeParams _
instance eqSubTreeParams :: Eq SubTreeParams where
eq = genericEq
instance showSubTreeParams :: Show SubTreeParams where
show = genericShow
------------------------------------------------------------------------
......
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