Tabs.purs 4.77 KB
Newer Older
1 2
-- TODO copy of Gargantext.Components.Nodes.Corpus.Tabs.Specs
module Gargantext.Components.Nodes.Annuaire.User.Contacts.Tabs where
3

4
import Gargantext.Prelude
5

6 7
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..))
8
import Data.Show.Generic (genericShow)
9
import Data.Tuple.Nested ((/\))
10
import Gargantext.Components.App.Data (Boxes)
11
import Gargantext.Components.DocsTable as DT
12
import Gargantext.Components.DocsTable.Types (Year)
13
import Gargantext.Components.NgramsTable as NT
14
import Gargantext.Components.NgramsTable.Core as NTC
15
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (ContactData')
16 17
import Gargantext.Components.Nodes.Lists.Types as LTypes
import Gargantext.Components.Nodes.Texts.Types as TTypes
18
import Gargantext.Components.Tab as Tab
James Laver's avatar
James Laver committed
19
import Gargantext.Ends (Frontends)
20
import Gargantext.Sessions (Session)
21
import Gargantext.Types (CTabNgramType(..), PTabNgramType(..), TabSubType(..), TabType(..))
22
import Gargantext.Utils.Reactix as R2
23 24
import Reactix as R
import Toestand as T
25

James Laver's avatar
James Laver committed
26 27
here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Annuaire.User.Contacts.Tabs"
28 29 30 31


data Mode = Patents | Books | Communication

32
derive instance Generic Mode _
33

34
instance Show Mode where
35 36
  show = genericShow

37
derive instance Eq Mode
38 39 40 41 42 43 44 45 46 47 48 49

modeTabType :: Mode -> PTabNgramType
modeTabType Patents = PTabPatents
modeTabType Books = PTabBooks
modeTabType Communication = PTabCommunication

-- TODO fix this type
modeTabType' :: Mode -> CTabNgramType
modeTabType' Patents = CTabAuthors
modeTabType' Books = CTabAuthors
modeTabType' Communication = CTabAuthors

50 51 52 53 54 55 56 57
type TabsProps =
  ( boxes         :: Boxes
  , cacheState    :: T.Box LTypes.CacheState
  , defaultListId :: Int
  , frontends     :: Frontends
  , nodeId        :: Int
  , session       :: Session
  , sidePanel     :: T.Box (Maybe (Record TTypes.SidePanel))
58
  )
59

60
tabs :: R2.Leaf TabsProps
61
tabs = R2.leafComponent tabsCpt
62
tabsCpt :: R.Component TabsProps
James Laver's avatar
James Laver committed
63
tabsCpt = here.component "tabs" cpt
64
  where
65 66
    cpt { boxes
        , cacheState
67
        , defaultListId
68 69 70
        , frontends
        , nodeId
        , session
71
        , sidePanel
72
        } _ = do
73
      activeTab <- T.useBox 0
74
      yearFilter <- T.useBox (Nothing :: Maybe Year)
75

76
      pure $ Tab.tabs { activeTab, tabs: tabs' yearFilter }
77
      where
78
        tabs' yearFilter =
James Laver's avatar
James Laver committed
79
          [ "Documents"     /\ docs
80 81 82
          , "Patents"       /\ ngramsView patentsView []
          , "Books"         /\ ngramsView booksView []
          , "Communication" /\ ngramsView commView []
James Laver's avatar
James Laver committed
83
          , "Trash"         /\ docs -- TODO pass-in trash mode
84 85
          ]
          where
86 87
            patentsView = { boxes
                          , cacheState
88 89 90
                          , defaultListId
                          , mode: Patents
                          , nodeId
91 92
                          , session
                          }
93 94
            booksView   = { boxes
                          , cacheState
95 96 97
                          , defaultListId
                          , mode: Books
                          , nodeId
98 99
                          , session
                          }
100 101
            commView    = { boxes
                          , cacheState
102 103 104
                          , defaultListId
                          , mode: Communication
                          , nodeId
105 106
                          , session
                          }
107
            chart       = mempty
108
            totalRecords = 4736 -- TODO
James Laver's avatar
James Laver committed
109
            docs = DT.docViewLayout
110 111
              { boxes
              , cacheState
112 113 114
              , chart
              , frontends
              , listId: defaultListId
115
              , mCorpusId: Nothing
116 117 118
              , nodeId
              , session
              , showSearch: true
119
              , sidePanel
120 121
              , tabType: TabPairing TabDocs
              , totalRecords
122
              , yearFilter
123
              }
124 125


126
type NgramsViewTabsProps = (
127 128
    boxes          :: Boxes
  , cacheState     :: T.Box LTypes.CacheState
129 130 131 132
  , defaultListId  :: Int
  , mode           :: Mode
  , nodeId         :: Int
  , session        :: Session
133
  )
134

135 136
ngramsView :: R2.Component NgramsViewTabsProps
ngramsView = R.createElement ngramsViewCpt
137
ngramsViewCpt :: R.Component NgramsViewTabsProps
James Laver's avatar
James Laver committed
138
ngramsViewCpt = here.component "ngramsView" cpt
139
  where
140 141
    cpt { boxes
        , cacheState
142 143 144
        , defaultListId
        , mode
        , nodeId
145
        , session } _ = do
146
      path <- T.useBox $ NTC.initialPageParams session nodeId [defaultListId] (TabDocument TabDocs)
147 148

      pure $ NT.mainNgramsTable {
149
          afterSync: \_ -> pure unit
150
        , boxes
151 152
        , cacheState
        , defaultListId
James Laver's avatar
James Laver committed
153
        , path
154 155
        , session
        , tabNgramType
156
        , tabType
157
        , withAutoUpdate: false
158
        } []
159 160 161
      where
        tabNgramType = modeTabType' mode
        tabType      = TabPairing $ TabNgramType $ modeTabType mode