Texts.purs 5.27 KB
Newer Older
1
module Gargantext.Components.Nodes.Texts where
2

3 4 5
import Prelude
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
6
import Data.Maybe (Maybe(..))
7
import Data.Tuple.Nested ((/\))
8
import Reactix as R
9 10
import Reactix.DOM.HTML as H

11
--------------------------------------------------------
12
import Gargantext.Components.DocsTable as DT
13
import Gargantext.Components.Loader (loader)
14
import Gargantext.Components.Node (NodePoly(..))
15 16 17
import Gargantext.Components.Nodes.Corpus (CorpusData, CorpusInfo(..), loadCorpus)
import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo)
import Gargantext.Components.Tab as Tab
18
import Gargantext.Components.Table as Table
James Laver's avatar
James Laver committed
19
import Gargantext.Ends (Frontends)
20
import Gargantext.Sessions (Session)
21
import Gargantext.Types (CTabNgramType(..), TabSubType(..), TabType(..))
22

James Laver's avatar
James Laver committed
23
type Props = ( frontends :: Frontends, session :: Session, nodeId :: Int )
24 25 26 27

textsLayout :: Record Props -> R.Element
textsLayout props = R.createElement textsLayoutCpt props []

28
------------------------------------------------------------------------
29
textsLayoutCpt :: R.Component Props
30
textsLayoutCpt = R.hooksComponent "G.C.Nodes.Texts.textsLayout" cpt where
James Laver's avatar
James Laver committed
31
  cpt {session,nodeId,frontends} _ = do
32
    pure $ loader {session, nodeId} loadCorpus paint
33 34
    where
      paint corpusData@{corpusId, corpusNode, defaultListId} =
35
        R.fragment [ Table.tableHeaderLayout headerProps, tabs' ]
36 37 38
        where
          NodePoly { name, date, hyperdata: CorpusInfo corpus } = corpusNode
          {desc, query, authors: user} = corpus
James Laver's avatar
James Laver committed
39
          tabs' = tabs {session, corpusId, corpusData, frontends}
40 41
          title = "Corpus " <> name
          headerProps = { title, desc, query, date, user }
42 43 44 45 46 47 48 49 50 51 52 53 54 55

data Mode = MoreLikeFav | MoreLikeTrash

derive instance genericMode :: Generic Mode _

instance showMode :: Show Mode where
  show = genericShow

derive instance eqMode :: Eq Mode

modeTabType :: Mode -> CTabNgramType
modeTabType MoreLikeFav    = CTabAuthors  -- TODO
modeTabType MoreLikeTrash  = CTabSources  -- TODO

James Laver's avatar
James Laver committed
56
type TabsProps = ( frontends :: Frontends, session :: Session, corpusId :: Int, corpusData :: CorpusData )
57 58 59 60 61 62 63

tabs :: Record TabsProps -> R.Element
tabs props = R.createElement tabsCpt props []

tabsCpt :: R.Component TabsProps
tabsCpt = R.hooksComponent "G.C.Nodes.Texts.tabs" cpt
  where
James Laver's avatar
James Laver committed
64
    cpt {frontends, session, corpusId, corpusData} _ = do
65 66 67 68 69
      (selected /\ setSelected) <- R.useState' 0
      pure $ Tab.tabs { tabs: tabs', selected }
      where
        tabs' = [ "Documents"     /\ docs,        "Trash"           /\ trash
                , "More like fav" /\ moreLikeFav, "More like trash" /\ moreLikeTrash ]
James Laver's avatar
James Laver committed
70
        docView' tabType = docView { frontends, session, corpusId, corpusData, tabType }
71 72 73 74 75 76 77
        docs = R.fragment [ docsHisto, docView' TabDocs ]
        docsHisto = histo { path, session }
          where path = { corpusId, tabType: TabCorpus TabDocs }
        moreLikeFav = docView' TabMoreLikeFav
        moreLikeTrash = docView' TabMoreLikeTrash
        trash = docView' TabTrash

James Laver's avatar
James Laver committed
78 79 80 81 82 83
type DocViewProps a =
  ( frontends :: Frontends
  , session :: Session
  , corpusId :: Int
  , corpusData :: CorpusData
  , tabType :: TabSubType a )
84 85 86 87 88 89 90

docView :: forall a. Record (DocViewProps a) -> R.Element
docView props = R.createElement docViewCpt props []

docViewCpt :: forall a. R.Component (DocViewProps a)
docViewCpt = R.hooksComponent "G.C.Nodes.Texts.docView" cpt
  where
James Laver's avatar
James Laver committed
91
    cpt {frontends, session, corpusId, corpusData: {defaultListId}, tabType} _children = do
92 93 94 95 96 97 98 99 100 101 102 103
      pure $ DT.docViewLayout $ params tabType
      where
        params :: forall b. TabSubType b -> Record DT.LayoutProps
        params TabDocs =
          { nodeId: corpusId
            -- ^ TODO merge nodeId and corpusId in DT
          , chart  : H.div {} []
          , tabType: TabCorpus TabDocs
          , totalRecords: 4737
          , listId: defaultListId
          , corpusId: Just corpusId
          , showSearch: true
James Laver's avatar
James Laver committed
104
          , frontends, session }
105 106 107 108 109 110 111 112 113
        params TabMoreLikeFav =
          { nodeId: corpusId
            -- ^ TODO merge nodeId and corpusId in DT
          , chart  : H.div {} []
          , tabType: TabCorpus TabMoreLikeFav
          , totalRecords: 4737
          , listId: defaultListId
          , corpusId: Just corpusId
          , showSearch: false
James Laver's avatar
James Laver committed
114
          , frontends, session }
115 116 117 118 119 120 121 122 123
        params TabMoreLikeTrash =
          { nodeId: corpusId
            -- ^ TODO merge nodeId and corpusId in DT
          , chart  : H.div {} []
          , tabType: TabCorpus TabMoreLikeTrash
          , totalRecords: 4737
          , listId: defaultListId
          , corpusId: Just corpusId
          , showSearch: false
James Laver's avatar
James Laver committed
124
          , frontends, session }
125 126 127 128 129 130 131 132 133
        params TabTrash =
          { nodeId: corpusId
            -- ^ TODO merge nodeId and corpusId in DT
          , chart  : H.div {} []
          , tabType: TabCorpus TabTrash
          , totalRecords: 4737
          , listId: defaultListId
          , corpusId: Nothing
          , showSearch: true
James Laver's avatar
James Laver committed
134
          , frontends, session }
135 136 137 138 139 140 141 142 143 144
        -- DUMMY
        params _ =
          { nodeId: corpusId
            -- ^ TODO merge nodeId and corpusId in DT
          , chart  : H.div {} []
          , tabType: TabCorpus TabTrash
          , totalRecords: 4737
          , listId: defaultListId
          , corpusId: Nothing
          , showSearch: true
James Laver's avatar
James Laver committed
145
          , frontends, session }