Tabs.purs 1.32 KB
Newer Older
1
module Gargantext.Components.Nodes.Corpus.Graph.Tabs where
2 3

import Prelude hiding (div)
4 5
import Data.Array (fromFoldable)
import Data.Tuple (Tuple(..), fst)
6
import Reactix as R
7
import Gargantext.Components.GraphExplorer.Types (GraphSideCorpus(..))
8
import Gargantext.Components.FacetsTable (TextQuery, docView)
9
import Gargantext.Components.Table as T
10
import Gargantext.Components.Tab as Tab
11
import Gargantext.Sessions (Session)
12

13
type Props = ( session :: Session, query :: TextQuery, sides :: Array GraphSideCorpus )
14

15 16
tabs :: Record Props -> R.Element
tabs props = R.createElement tabsCpt props []
17 18

-- TODO no need for Children here
19 20 21
tabsCpt :: R.Component Props
tabsCpt = R.hooksComponent "G.P.Corpus.Graph.Tabs.tabs" cpt
  where
22
    cpt {session, query, sides} _ = do
23 24 25
      active <- R.useState' 0
      pure $ Tab.tabs {tabs: tabs', selected: fst active}
      where
26
        tabs' = fromFoldable $ tab session query <$> sides
27

28 29
tab :: Session -> TextQuery -> GraphSideCorpus -> Tuple String R.Element
tab session query (GraphSideCorpus {corpusId: nodeId, corpusLabel, listId}) =
30
  Tuple corpusLabel (docView dvProps)
31
  where
32
    dvProps = {session, nodeId, listId, query, chart, totalRecords: 4736, container}
33 34
    -- TODO totalRecords: probably need to insert a corpusLoader.
    chart = mempty
35
    container = T.graphContainer {title: corpusLabel}
36