NgramsTable.purs 2.39 KB
Newer Older
1 2 3 4 5 6 7
-- TODO copy of Gargantext.Pages.Corpus.Tabs.Ngrams.NgramsTable where
module Gargantext.Pages.Annuaire.User.Contacts.Tabs.Ngrams.NgramsTable
  (Mode(..), ngramsTableSpec)
  where

import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
8
import Data.Maybe (Maybe(..))
9
import Effect.Aff (Aff)
10
import React (ReactElement)
11
import React as React
12
import Thermite (Render, Spec, createClass, defaultPerformAction, simpleSpec)
13

14
import Gargantext.Components.NgramsTable as NT
15
import Gargantext.Prelude
16
import Gargantext.Config (PTabNgramType(..), Offset, Limit, End(..), Path(..), TabSubType(..), TabType(..), toUrl)
17
import Gargantext.Config.REST (get)
18
import Gargantext.Components.Loader as Loader
19
import Gargantext.Pages.Annuaire.User.Contacts.Types (Contact)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

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

35 36 37 38
type Props = NT.Props Contact Mode

-- TODO: Move to Components.NgramsTable
loadPage :: NT.PageParams -> Aff NT.VersionedNgramsTable
39
loadPage {nodeId, listIds, tabType, params: {offset, limit}} =
40
  get $ toUrl Back (GetNgrams tabType offset limit listIds Nothing) (Just nodeId)
41
  -- TODO this ignores orderBy
42

43 44
-- TODO: Move to Components.NgramsTable?
ngramsLoaderClass :: Loader.LoaderClass NT.PageParams NT.VersionedNgramsTable
45
ngramsLoaderClass = Loader.createLoaderClass "ContactsNgramsLoader" loadPage
46

47 48
-- TODO: Move to Components.NgramsTable?
ngramsLoader :: Loader.Props' NT.PageParams NT.VersionedNgramsTable -> ReactElement
49 50
ngramsLoader props = React.createElement ngramsLoaderClass props []

51 52
-- TODO: Move to Components.NgramsTable?
ngramsTableClass :: Loader.InnerClass NT.PageParams NT.VersionedNgramsTable
53 54
ngramsTableClass = createClass "ContactsNgramsTable" NT.ngramsTableSpec NT.initialState

55 56 57 58 59
ngramsTableSpec :: Spec {} Props Void
ngramsTableSpec = simpleSpec defaultPerformAction render
  where
    render :: Render {} Props Void
    render _ {path: nodeId, mode} _ _ =
60
      -- TODO: ignored loaded
61
      [ ngramsLoader { path: NT.initialPageParams nodeId [] tabType
62
                     , component: ngramsTableClass
63
                     } ]
64 65
      where
        tabType = TabPairing $ TabNgramType $ modeTabType mode