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

3
import Data.Tuple (fst)
4
import Effect (Effect)
5
import Effect.Aff (launchAff_)
6
import Reactix as R
7
import Record as Record
8
------------------------------------------------------------------------
9
import Gargantext.AsyncTasks as GAT
10
import Gargantext.Components.NgramsTable.Loader (clearCache)
11
import Gargantext.Components.Node (NodePoly(..))
12 13 14
import Gargantext.Components.Nodes.Corpus (loadCorpusWithChild)
import Gargantext.Components.Nodes.Corpus.Types (getCorpusInfo, CorpusInfo(..), Hyperdata(..))
import Gargantext.Components.Nodes.Lists.Tabs as Tabs
15
import Gargantext.Components.Nodes.Lists.Types as NT
16
import Gargantext.Components.Table as Table
17
import Gargantext.Hooks.Loader (useLoader)
18
import Gargantext.Prelude
19
import Gargantext.Sessions (Session, sessionId, getCacheState, setCacheState)
20 21
import Gargantext.Utils.Reactix as R2

22
thisModule :: String
23
thisModule = "Gargantext.Components.Nodes.Lists"
24
------------------------------------------------------------------------
25
------------------------------------------------------------------------
26

27
type Props = (
28
    asyncTasks    :: GAT.Reductor
29 30
  , nodeId        :: Int
  , session       :: Session
31
  , sessionUpdate :: Session -> Effect Unit
32
  )
33 34 35 36 37

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

listsLayoutCpt :: R.Component Props
38
listsLayoutCpt = R.hooksComponentWithModule thisModule "listsLayout" cpt
39
  where
40
    cpt path@{ nodeId, session } _ = do
41 42
      let sid = sessionId session

43
      pure $ listsLayoutWithKey $ Record.merge path { key: show sid <> "-" <> show nodeId }
44 45 46 47 48 49 50 51 52 53

type KeyProps = (
  key :: String
  | Props
  )

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

listsLayoutWithKeyCpt :: R.Component KeyProps
54
listsLayoutWithKeyCpt = R.hooksComponentWithModule thisModule "listsLayoutWithKey" cpt
55
  where
56
    cpt { asyncTasks, nodeId, session, sessionUpdate } _ = do
57 58
      let path = { nodeId, session }

59
      cacheState <- R.useState' $ getCacheState NT.CacheOn session nodeId
60

61
      useLoader path loadCorpusWithChild $
62
        \corpusData@{ corpusId, corpusNode: NodePoly poly, defaultListId } ->
63 64 65
          let { date, hyperdata : Hyperdata h, name } = poly
              CorpusInfo { authors, desc, query } = getCorpusInfo h.fields
          in
66 67
          R.fragment [
            Table.tableHeaderLayout {
68
                afterCacheStateChange
69 70 71
              , cacheState
              , date
              , desc
72
              , key: "listsLayoutWithKey-header-" <> (show $ fst cacheState)
73 74 75 76
              , query
              , title: "Corpus " <> name
              , user: authors }
          , Tabs.tabs {
77 78
               asyncTasks
             , cacheState
79 80
             , corpusData
             , corpusId
81
             , key: "listsLayoutWithKey-tabs-" <> (show $ fst cacheState)
82 83
             , session }
          ]
84 85 86 87
      where
        afterCacheStateChange cacheState = do
          launchAff_ $ clearCache unit
          sessionUpdate $ setCacheState session nodeId cacheState
88
------------------------------------------------------------------------