Corpus.purs 2.25 KB
Newer Older
1
module Gargantext.Pages.Corpus where
2

3

4
import Data.Maybe (Maybe(..))
5
import Effect.Aff (Aff)
6 7
import React as React
import React (ReactClass, ReactElement)
8
import Thermite (Spec, Render, simpleSpec, createClass, defaultPerformAction)
9
--------------------------------------------------------
10
import Gargantext.Prelude
11
import Gargantext.Components.Node (NodePoly(..))
12 13
import Gargantext.Components.Loader as Loader
import Gargantext.Components.Loader (createLoaderClass)
14
import Gargantext.Components.Table as Table
15 16
import Gargantext.Config      (toUrl, NodeType(..), End(..))
import Gargantext.Config.REST (get)
17
import Gargantext.Pages.Corpus.Tabs.Types (CorpusInfo(..))
18
import Gargantext.Pages.Corpus.Tabs.Types (Props) as Tabs
19
import Gargantext.Pages.Corpus.Tabs.Specs (pureTabs) as Tabs
20
-------------------------------------------------------------------
Nicolas Pouillard's avatar
Nicolas Pouillard committed
21 22
type Props = Tabs.Props

23
------------------------------------------------------------------------
24 25
layout :: Spec {} {nodeId :: Int} Void
layout = simpleSpec defaultPerformAction render
26
  where
27 28
    render :: Render {} {nodeId :: Int} Void
    render _ {nodeId} _ _ =
29
      [ corpusLoader { path: nodeId
30
                     , component: createClass "Layout" layout' (const {})
31
                     } ]
32

33 34
layout' :: Spec {} Props Void
layout' = corpusHeaderSpec <> Tabs.pureTabs
35 36 37 38 39 40

corpusHeaderSpec :: Spec {} Props Void
corpusHeaderSpec = simpleSpec defaultPerformAction render
  where
    render :: Render {} Props Void
    render dispatch {loaded} _ _ =
41 42 43 44 45 46 47 48 49 50 51 52
      Table.renderTableHeaderLayout
        { title: "Corpus " <> title
        , desc:  corpus.desc
        , query: corpus.query
        , date:  date'
        , user:  corpus.authors
        }
      where
        NodePoly { name: title
                 , date: date'
                 , hyperdata : CorpusInfo corpus
                 }
53
          = loaded
54 55 56

------------------------------------------------------------------------

57
getCorpus :: Int -> Aff (NodePoly CorpusInfo)
58
getCorpus = get <<< toUrl Back Corpus <<< Just
59

60
corpusLoaderClass :: ReactClass (Loader.Props Int (NodePoly CorpusInfo))
61
corpusLoaderClass = createLoaderClass "CorpusLoader" getCorpus
62

63
corpusLoader :: Loader.Props' Int (NodePoly CorpusInfo) -> ReactElement
64
corpusLoader props = React.createElement corpusLoaderClass props []