Rename.purs 1.02 KB
Newer Older
1
module Gargantext.Components.Forest.Tree.Node.Action.Rename where
2

3
import Data.Argonaut (class EncodeJson, jsonEmptyObject, (:=), (~>))
4
import Data.Maybe (Maybe(..))
5 6
import Effect.Aff (Aff)
import Prelude (($))
7
import Gargantext.Components.Forest.Tree.Node.Action
8
import Gargantext.Types as GT
9
import Gargantext.Types (ID)
10
import Gargantext.Routes as GR
11
import Gargantext.Sessions (Session, put)
12

13 14 15
------------------------------------------------------------------------
rename :: Session -> ID -> RenameValue -> Aff (Array ID)
rename session renameNodeId =
16
  put session $ GR.NodeAPI GT.Node (Just renameNodeId) "rename"
17

18 19 20 21
renameAction :: String -> Action
renameAction newName = RenameNode newName

------------------------------------------------------------------------
22
newtype RenameValue = RenameValue
23
  { text :: String }
24 25

instance encodeJsonRenameValue :: EncodeJson RenameValue where
26
  encodeJson (RenameValue {text})
27
     = "name" := text
28 29
    ~> jsonEmptyObject

30
------------------------------------------------------------------------