Actions.purs 1.9 KB
Newer Older
1
module Gargantext.Pages.Layout.Specs.AddCorpus.Actions where
2

Sudhir Kumar's avatar
Sudhir Kumar committed
3
import Control.Monad.Cont.Trans (lift)
4
import Data.Argonaut (class EncodeJson, jsonEmptyObject, (:=), (~>))
Sudhir Kumar's avatar
Sudhir Kumar committed
5
import Effect.Aff (Aff)
Sudhir Kumar's avatar
Sudhir Kumar committed
6
import Effect.Class (liftEffect)
7 8
import Routing.Hash (setHash)
import Thermite (PerformAction, modifyState)
9

10 11 12 13 14
import Gargantext.Prelude
import Gargantext.Config.REST (post)
import Gargantext.Components.Modals.Modal (modalHide)
import Gargantext.Pages.Layout.Specs.AddCorpus.States (Response, State)

15
data Action
Nicolas Pouillard's avatar
Nicolas Pouillard committed
16
  = SelectDatabase Boolean
17 18 19 20
  | UnselectDatabase Boolean
  | LoadDatabaseDetails
  | GO

21
performAction :: PerformAction State {} Action
22
performAction (SelectDatabase selected) _ _ = void do
23
  modifyState $ _ { select_database = selected }
24 25

performAction (UnselectDatabase unselected) _ _ = void do
26
  modifyState $ _ { unselect_database = unselected }
27

28
performAction (LoadDatabaseDetails) _ _ = do
29
  res <- lift $ getDatabaseDetails $ QueryString { query_query: "string",query_name: ["Pubmed"]}
30
  void $ modifyState $ _ {response = res}
31

32 33 34 35
performAction GO _ _ = do
  liftEffect $ setHash "/corpus"
  liftEffect $ modalHide "addCorpus"
  pure unit
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59


newtype QueryString = QueryString
  {
    query_query :: String
  , query_name :: Array String
  }

queryString :: QueryString
queryString = QueryString
  {
  query_query: "string",
  query_name: [
    "Pubmed"
  ]
  }


instance encodeJsonQueryString :: EncodeJson QueryString where
  encodeJson (QueryString obj) =
    "query_query"       := obj.query_query
    ~> "query_name"        := obj.query_name
    ~> jsonEmptyObject

60
getDatabaseDetails :: QueryString -> Aff (Array Response)
61
getDatabaseDetails reqBody = do
62 63
  -- TODO let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MTk5OTg1ODMsInVzZXJfaWQiOjUsImVtYWlsIjoiYWxleGFuZHJlLmRlbGFub2VAaXNjcGlmLmZyIiwidXNlcm5hbWUiOiJkZXZlbG9wZXIifQ.Os-3wuFNSmRIxCZi98oFNBu2zqGc0McO-dgDayozHJg"
  post "http://localhost:8009/count" reqBody