Node.purs 1.26 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
    pure $ NodePoly { id
                    , date
                    , hyperdata: hyperdata'
                    , name
                    , parentId
                    , typename
                    , userId
                    }
40

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

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