Tabs.purs 2.92 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 5 6 7

import Prelude hiding (div)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..))
8
import Data.Tuple (fst)
9
import Data.Tuple.Nested ((/\))
10
import Reactix as R
11 12 13
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.Tab as Tab
14
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (ContactData)
James Laver's avatar
James Laver committed
15
import Gargantext.Ends (Frontends)
16 17
import Gargantext.Sessions (Session)
import Gargantext.Types (TabType(..), TabSubType(..), CTabNgramType(..), PTabNgramType(..))
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39


data Mode = Patents | Books | Communication

derive instance genericMode :: Generic Mode _

instance showMode :: Show Mode where
  show = genericShow

derive instance eqMode :: Eq Mode

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

40
type TabsProps =
41 42
  ( nodeId :: Int
  , contactData :: ContactData
James Laver's avatar
James Laver committed
43
  , frontends :: Frontends
44
  , session :: Session )
45

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

49
tabsCpt :: R.Component TabsProps
50 51
tabsCpt = R.hooksComponent "G.P.Annuaire.User.Contacts.Tabs.tabs" cpt
  where
James Laver's avatar
James Laver committed
52
    cpt {frontends, nodeId, contactData: {defaultListId}, session} _ = do
53 54 55 56 57 58 59 60 61 62 63 64
      active <- R.useState' 0
      pure $
        Tab.tabs { tabs: tabs', selected: fst active }
      where
        tabs' =
          [ "Documents"     /\ docs
          , "Patents"       /\ ngramsView patentsView
          , "Books"         /\ ngramsView booksView
          , "Communication" /\ ngramsView commView
          , "Trash"         /\ docs -- TODO pass-in trash mode
          ]
          where
65
            patentsView = {session, defaultListId, nodeId, mode: Patents}
66 67 68
            booksView   = {session, defaultListId, nodeId, mode: Books}
            commView    = {session, defaultListId, nodeId, mode: Communication}
            chart       = mempty
69
            totalRecords = 4736 -- TODO
70
            docs = DT.docViewLayout
James Laver's avatar
James Laver committed
71
              { frontends, session, nodeId, chart, totalRecords
72 73 74 75 76 77
              , tabType: TabPairing TabDocs
              , listId: defaultListId
              , corpusId: Nothing
              , showSearch: true }


78
type NgramsViewTabsProps =
79
  ( session :: Session
80 81 82 83
  , mode :: Mode
  , defaultListId :: Int
  , nodeId :: Int )

84
ngramsView :: Record NgramsViewTabsProps -> R.Element
85
ngramsView {session,mode, defaultListId, nodeId} =
86
  NT.mainNgramsTable
87
  { nodeId, defaultListId, tabType, session, tabNgramType }
88 89
  where
    tabNgramType = modeTabType' mode
90
    tabType      = TabPairing $ TabNgramType $ modeTabType mode