States.purs 1003 Bytes
Newer Older
1
module Gargantext.Pages.Layout.Specs.AddCorpus.States where
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

import Prelude hiding (div)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, jsonEmptyObject, (.?), (:=), (~>))

type State =
  { select_database :: Boolean
  , unselect_database :: Boolean  --  dummy state
  , response :: Array Response
  }

newtype Response = Response
  {
    count :: Int
  , name :: String
  }

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

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


instance encodeJsonQuery :: EncodeJson Query where
  encodeJson (Query post)
     = "query_query" := post.query_query
    ~> "query_name" := post.query_name
    ~> jsonEmptyObject



34 35 36 37 38 39 40 41 42 43 44 45 46 47
instance decodeJsonresponse :: DecodeJson Response where
  decodeJson json = do
    obj   <- decodeJson json
    count <- obj .? "count"
    name  <- obj .? "name"
    pure $ Response {count,name }

initialState :: State
initialState =
  {
    select_database   : true
  , unselect_database : true
  , response : []
  }