Tabs.purs 4.33 KB
Newer Older
Alexandre Delanoë's avatar
Alexandre Delanoë committed
1
-- TODO copy of Gargantext.Components.Nodes.Corpus.Tabs.Specs
2
module Gargantext.Components.Nodes.Annuaire.Tabs where
Alexandre Delanoë's avatar
Alexandre Delanoë committed
3 4

import Prelude hiding (div)
5

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

James Laver's avatar
James Laver committed
29 30
here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Annuaire.User.Contacts.Tabs"
Alexandre Delanoë's avatar
Alexandre Delanoë committed
31 32 33

data Mode = Patents | Books | Communication

34
derive instance Generic Mode _
Alexandre Delanoë's avatar
Alexandre Delanoë committed
35

36
instance Show Mode where
Alexandre Delanoë's avatar
Alexandre Delanoë committed
37 38
  show = genericShow

39
derive instance Eq Mode
Alexandre Delanoë's avatar
Alexandre Delanoë committed
40 41 42 43 44 45 46 47 48 49 50 51

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

James Laver's avatar
James Laver committed
52
type TabsProps =
53 54 55 56 57 58 59
  ( boxes       :: Boxes
  , cacheState  :: T.Box LTypes.CacheState
  , contactData :: ContactData
  , frontends   :: Frontends
  , nodeId      :: Int
  , session     :: Session
  , sidePanel   :: T.Box (Maybe (Record TextsT.SidePanel))
Alexandre Delanoë's avatar
Alexandre Delanoë committed
60 61
  )

James Laver's avatar
James Laver committed
62
tabs :: R2.Leaf TabsProps
Alexandre Delanoë's avatar
Alexandre Delanoë committed
63 64
tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component TabsProps
James Laver's avatar
James Laver committed
65 66
tabsCpt = here.component "tabs" cpt where
  cpt props _ = do
67
    activeTab <- T.useBox 0
68
    yearFilter <- T.useBox (Nothing :: Maybe Year)
69

70
    pure $ Tab.tabs { activeTab, tabs: tabs' yearFilter props }
71
  tabs' yearFilter props@{ boxes, sidePanel } =
72
    [ "Documents"     /\ docs
James Laver's avatar
James Laver committed
73 74 75
    , "Patents"       /\ ngramsView (viewProps Patents)
    , "Books"         /\ ngramsView (viewProps Books)
    , "Communication" /\ ngramsView (viewProps Communication)
76
    , "Trash"         /\ docs -- TODO pass-in trash mode
James Laver's avatar
James Laver committed
77
    ] where
78 79
      viewProps mode = Record.merge props { defaultListId: props.contactData.defaultListId
                                          , mode }
James Laver's avatar
James Laver committed
80
      totalRecords = 4736 -- TODO lol
81
      docs = DT.docViewLayout (Record.merge { boxes, sidePanel } $ Record.merge dtCommon dtExtra)
James Laver's avatar
James Laver committed
82
      dtCommon = RX.pick props :: Record DTCommon
83 84
      dtExtra =
        { chart: mempty
James Laver's avatar
James Laver committed
85
        , listId: props.contactData.defaultListId
86 87 88 89
        , mCorpusId: Nothing
        , showSearch: true
        , tabType: TabPairing TabDocs
        , totalRecords
90
        , yearFilter
James Laver's avatar
James Laver committed
91 92 93
        }

type DTCommon =
94
  ( cacheState        :: T.Box LTypes.CacheState
95
  -- , contactData       :: ContactData
James Laver's avatar
James Laver committed
96
  , frontends         :: Frontends
Alexandre Delanoë's avatar
Alexandre Delanoë committed
97 98
  , nodeId            :: Int
  , session           :: Session
99
  -- , sidePanel    :: T.Box (Record SidePanel)
Alexandre Delanoë's avatar
Alexandre Delanoë committed
100 101
  )

102 103 104 105 106
type NgramsViewTabsProps =
  ( defaultListId :: Int
  , mode          :: Mode
  | TabsProps )

James Laver's avatar
James Laver committed
107 108
ngramsView :: R2.Leaf NgramsViewTabsProps
ngramsView props = R.createElement ngramsViewCpt props []
Alexandre Delanoë's avatar
Alexandre Delanoë committed
109
ngramsViewCpt :: R.Component NgramsViewTabsProps
James Laver's avatar
James Laver committed
110
ngramsViewCpt = here.component "ngramsView" cpt where
111
  cpt props@{ defaultListId, mode, nodeId, session } _ = do
112
    path <- T.useBox $
James Laver's avatar
James Laver committed
113 114
      NTC.initialPageParams session nodeId
      [ defaultListId ] (TabDocument TabDocs)
115

James Laver's avatar
James Laver committed
116 117 118
    pure $ NT.mainNgramsTable (props' path) [] where
      most = RX.pick props :: Record NTCommon
      props' path =
119
        (Record.merge most
120 121 122 123
          { afterSync
          , path
          , tabType:        TabPairing (TabNgramType $ modeTabType mode)
          , tabNgramType:   modeTabType' mode
124
          , withAutoUpdate: false }) :: Record NT.MainNgramsTableProps
125
        where
James Laver's avatar
James Laver committed
126 127 128 129
          afterSync :: Unit -> Aff Unit
          afterSync _ = pure unit

type NTCommon =
130 131 132 133
  ( boxes         :: Boxes
  , cacheState    :: T.Box LTypes.CacheState
  , defaultListId :: Int
  , session       :: Session
James Laver's avatar
James Laver committed
134
  )