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

3 4 5 6
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>))
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Show (genericShow)
7
import Data.Maybe (Maybe(..))
8
import Data.Newtype (class Newtype)
9
import Effect.Aff (Aff)
10 11
import Prelude hiding (div)

12
import Gargantext.Components.Lang (Lang)
13 14
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get, put, post, delete)
15 16
import Gargantext.Routes as GR
import Gargantext.Types  as GT
17

18
data Action = CreateSubmit String GT.NodeType
19
            | DeleteNode
20
            | UpdateNode  GT.AsyncTaskWithType
21
            | SearchQuery GT.AsyncTaskWithType
22
            | Submit      String
23
            | UploadFile  GT.NodeType FileType (Maybe String) UploadFileContents
24
            | RefreshTree
25

26
-----------------------------------------------------
27 28
-- TODO Delete with asyncTaskWithType
deleteNode :: Session -> GT.ID -> Aff GT.ID
29
deleteNode session nodeId = delete session $ NodeAPI GT.Node (Just nodeId) ""
30
-----------------------------------------------------------------------
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

type Props =
  ( dispatch :: Action -> Aff Unit
  , id       :: Int
  , nodeType :: GT.NodeType
  , session  :: Session
  )

-- TODO remove these types from here

data FileType = CSV | CSV_HAL | WOS | PresseRIS

derive instance genericFileType :: Generic FileType _

instance eqFileType :: Eq FileType where
    eq = genericEq

instance showFileType :: Show FileType where
    show = genericShow


newtype UploadFileContents = UploadFileContents String