Node.purs 1.27 KB
Newer Older
1 2 3 4
module Gargantext.Components.Node 
  where

import Gargantext.Prelude
5
import Data.Argonaut (class DecodeJson, decodeJson, (.:))
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

newtype NodePoly a =
  NodePoly { id :: Int
           , typename :: Int
           , userId   :: Int
           , parentId  :: Int
           , name      :: String
           , date      :: String
           , hyperdata :: a
           }


instance decodeNodePoly :: (DecodeJson a)
  => DecodeJson (NodePoly a) where
  decodeJson json = do
    obj <- decodeJson json
22 23 24 25 26 27 28 29
    id        <- obj .: "id"
    typename  <- obj .: "typename"
    userId    <- obj .: "userId"
    parentId  <- obj .: "parentId"
    name      <- obj .: "name"
    date      <- obj .: "date"

    hyperdata  <- obj .: "hyperdata"
30
    hyperdata' <- decodeJson hyperdata
31

32 33 34 35 36 37 38 39 40
    pure $ NodePoly  { id : id
                 , typename : typename
                 , userId   : userId
                 , parentId : parentId
                 , name     : name
                 , date     : date
                 , hyperdata: hyperdata'
                 }

41 42 43 44 45
newtype HyperdataList = HyperdataList { preferences :: String}

instance decodeHyperdataList :: DecodeJson HyperdataList where
  decodeJson json = do
    obj <- decodeJson json
46
    pref <- obj .: "preferences"
47
    pure $ HyperdataList { preferences : pref}
48