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
48
49
50
51
module Gargantext.Components.Node
where
import Data.Eq.Generic (genericEq)
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe)
import Data.Newtype (class Newtype)
import Gargantext.Prelude
import Simple.JSON as JSON
type NodePolyCommon a =
( id :: Int
, typename :: Int
, name :: String
, date :: String
, hyperdata :: a )
newtype NodePoly a =
NodePoly { userId :: Int
, parentId :: Maybe Int
| NodePolyCommon a
}
derive instance Generic (NodePoly a) _
derive instance Newtype (NodePoly a) _
instance Eq a => Eq (NodePoly a) where eq = genericEq
instance JSON.ReadForeign a => JSON.ReadForeign (NodePoly a) where
readImpl f = do
inst :: { user_id :: Int, parent_id :: Maybe Int | NodePolyCommon a } <- JSON.readImpl f
pure $ NodePoly { id: inst.id
, typename: inst.typename
, userId: inst.user_id
, parentId: inst.parent_id
, name: inst.name
, date: inst.date
, hyperdata: inst.hyperdata }
instance JSON.WriteForeign a => JSON.WriteForeign (NodePoly a) where
writeImpl (NodePoly np) = do
JSON.writeImpl { user_id : np.userId
, parent_id : np.parentId
, id : np.id
, typename : np.typename
, name : np.name
, date : np.date
, hyperdata : np.hyperdata}
newtype HyperdataList = HyperdataList { preferences :: Maybe String }
derive instance Generic HyperdataList _
derive instance Newtype HyperdataList _
derive instance Eq HyperdataList
derive newtype instance JSON.ReadForeign HyperdataList