Lists.purs 2 KB
Newer Older
1
module Gargantext.Components.Nodes.Lists where
2 3

import Reactix as R
4
------------------------------------------------------------------------
5
import Gargantext.Components.Node (NodePoly(..))
6 7 8
import Gargantext.Components.Nodes.Corpus (loadCorpusWithChild)
import Gargantext.Components.Nodes.Corpus.Types (getCorpusInfo, CorpusInfo(..), Hyperdata(..))
import Gargantext.Components.Nodes.Lists.Tabs as Tabs
9
import Gargantext.Components.Table as Table
10
import Gargantext.Hooks.Loader (useLoader)
11
import Gargantext.Prelude
12
import Gargantext.Sessions (Session, sessionId)
13
------------------------------------------------------------------------
14
------------------------------------------------------------------------
15

16 17 18 19
type Props = (
    nodeId :: Int
  , session :: Session
  )
20 21 22 23 24

listsLayout :: Record Props -> R.Element
listsLayout props = R.createElement listsLayoutCpt props []

listsLayoutCpt :: R.Component Props
25
listsLayoutCpt = R.hooksComponent "G.C.N.L.listsLayout" cpt
26
  where
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    cpt path@{ nodeId, session } _ = do
      let sid = sessionId session

      pure $ listsLayoutWithKey { key: show sid <> "-" <> show nodeId, nodeId, session }

type KeyProps = (
  key :: String
  | Props
  )

listsLayoutWithKey :: Record KeyProps -> R.Element
listsLayoutWithKey props = R.createElement listsLayoutWithKeyCpt props []

listsLayoutWithKeyCpt :: R.Component KeyProps
listsLayoutWithKeyCpt = R.hooksComponent "G.C.N.L.listsLayoutWithKey" cpt
  where
    cpt { nodeId, session } _ = do
      let path = { nodeId, session }

46
      useLoader path loadCorpusWithChild $
47 48
        \corpusData@{ corpusId, corpusNode: NodePoly poly, defaultListId } ->
              let { date, hyperdata : Hyperdata h, name } = poly
49 50
                  CorpusInfo {desc,query,authors} = getCorpusInfo h.fields
           in
51 52
          R.fragment
          [ Table.tableHeaderLayout
53
            { title: "Corpus " <> name, desc, query, user:authors, date }
54
         , Tabs.tabs {session, corpusId, corpusData}]
55
------------------------------------------------------------------------