1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Gargantext.Components.Node
where
import Gargantext.Prelude
import Data.Argonaut (class DecodeJson, decodeJson, (.:), (.:?), (.!=))
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
id <- obj .: "id"
typename <- obj .: "typename"
userId <- obj .: "userId"
parentId <- obj .: "parentId"
name <- obj .: "name"
date <- obj .: "date"
hyperdata <- obj .: "hyperdata"
hyperdata' <- decodeJson hyperdata
pure $ NodePoly { id
, date
, hyperdata: hyperdata'
, name
, parentId
, typename
, userId
}
newtype HyperdataList = HyperdataList { preferences :: String }
instance decodeHyperdataList :: DecodeJson HyperdataList where
decodeJson json = do
obj <- decodeJson json
pref <- obj .:? "preferences" .!= ""
pure $ HyperdataList { preferences : pref }