Update.purs 2.35 KB
Newer Older
1 2
module Gargantext.Components.Forest.Tree.Node.Action.Update where

3 4
import Data.Tuple.Nested ((/\))
import Data.Maybe (Maybe(..))
5
import Effect.Aff (Aff)
6 7 8 9
import Gargantext.Components.Forest.Tree.Node.Action (Action(..))
import Gargantext.Components.Forest.Tree.Node.Action.Update.Types
import Gargantext.Components.Forest.Tree.Node.Tools (formChoiceSafe, submitButton, panel)
import Gargantext.Types (NodeType(..), ID)
10
import Gargantext.Types  as GT
11
import Gargantext.Prelude (Unit, bind, ($), pure)
12
import Gargantext.Sessions (Session, post)
13
import Gargantext.Routes as GR
14 15
import Reactix as R
import Reactix.DOM.HTML as H
16 17


18
updateRequest :: UpdateNodeParams -> Session -> ID -> Aff GT.AsyncTaskWithType
19 20
updateRequest updateNodeParams session nodeId = do
  task <- post session p updateNodeParams
21
  pure $ GT.AsyncTaskWithType {task, typ: GT.UpdateNode }
22
    where
23
      p = GR.NodeAPI GT.Node (Just nodeId) "update"
24

25
----------------------------------------------------------------------
26 27 28 29
update ::  NodeType
       -> (Action -> Aff Unit)
       ->  R.Hooks R.Element
update NodeList dispatch = do
30
  meth @( methodList /\ setMethod  ) <- R.useState' Basic
31 32 33
  pure $ panel [ -- H.text "Update with"
                formChoiceSafe [Basic, Advanced, WithModel] Basic setMethod
               ]
34
               (submitButton (UpdateNode $ UpdateNodeParamsList {methodList}) dispatch)
35

36
update Graph dispatch = do
37
  meth @( methodGraph /\ setMethod  ) <- R.useState' Order1
38 39 40
  pure $ panel [ -- H.text "Update with"
                formChoiceSafe [Order1, Order2] Order1 setMethod
               ]
41
               (submitButton (UpdateNode $ UpdateNodeParamsGraph {methodGraph}) dispatch)
42

43
update Texts dispatch  = do
44
  meth @( methodTexts /\ setMethod  ) <- R.useState' NewNgrams
45 46 47
  pure $ panel [ -- H.text "Update with"
                formChoiceSafe [NewNgrams, NewTexts, Both] NewNgrams setMethod
               ]
48
               (submitButton (UpdateNode $ UpdateNodeParamsTexts {methodTexts}) dispatch)
49

50
update Dashboard dispatch  = do
51
  meth @( methodBoard /\ setMethod  ) <- R.useState' All
52
  pure $ panel [ -- H.text "Update with"
53
                formChoiceSafe [All, Sources, Authors, Institutes, Ngrams] All setMethod
54
               ]
55
               (submitButton (UpdateNode $ UpdateNodeParamsBoard {methodBoard}) dispatch)
56

57
update _     _  = pure $ H.div {} []
58 59

-- fragmentPT $ "Update " <> show nodeType