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

3

4
import Data.Either (Either(..))
5 6
import Data.Lens (Lens', Prism', lens, prism)
import Data.Maybe (maybe)
7
import Effect.Aff (Aff)
8 9 10 11
import React as React
import React (ReactClass, ReactElement)
import Thermite ( Render, Spec, createClass, defaultPerformAction, focus
                , simpleSpec, noState )
12
--------------------------------------------------------
13
import Gargantext.Prelude
14
import Gargantext.Components.Node (NodePoly(..))
15 16
import Gargantext.Components.Loader as Loader
import Gargantext.Components.Loader (createLoaderClass)
17
import Gargantext.Components.Table as Table
18 19
import Gargantext.Config      (toUrl, NodeType(..), End(..))
import Gargantext.Config.REST (get)
20 21 22 23 24
import Gargantext.Pages.Corpus.Tabs.Types (CorpusInfo(..), corpusInfoDefault)
import Gargantext.Pages.Corpus.Tabs.Types (Props) as Tabs
import Gargantext.Pages.Corpus.Tabs.States (State, initialState) as Tabs
import Gargantext.Pages.Corpus.Tabs.Actions (Action) as Tabs
import Gargantext.Pages.Corpus.Tabs.Specs (statefulTabs) as Tabs
25
-------------------------------------------------------------------
Nicolas Pouillard's avatar
Nicolas Pouillard committed
26 27
type Props = Tabs.Props

28
type State = { tabsView    :: Tabs.State
29
             }
30 31

initialState :: State
32
initialState = { tabsView    : Tabs.initialState
33 34 35
               }

------------------------------------------------------------------------
36 37
_tabsView :: forall a b. Lens' { tabsView :: a | b } a
_tabsView = lens (\s -> s.tabsView) (\s ss -> s{tabsView = ss})
38
------------------------------------------------------------------------
39

40
data Action
41
  = TabsA   Tabs.Action
42

43 44
_tabsAction :: Prism' Action Tabs.Action
_tabsAction = prism TabsA \ action ->
45
  case action of
46
    TabsA taction -> Right taction
47 48
    -- _-> Left action

49
------------------------------------------------------------------------
50 51
layout :: Spec {} {nodeId :: Int} Void
layout = simpleSpec defaultPerformAction render
52
  where
53 54
    render :: Render {} {nodeId :: Int} Void
    render _ {nodeId} _ _ =
55 56 57
      [ corpusLoader { path: nodeId
                     , component: createClass "Layout" layout' initialState
                     } ]
58 59 60 61 62 63 64 65 66 67

layout' :: Spec State Props Action
layout' = noState corpusHeaderSpec
       <> focus _tabsView _tabsAction Tabs.statefulTabs

corpusHeaderSpec :: Spec {} Props Void
corpusHeaderSpec = simpleSpec defaultPerformAction render
  where
    render :: Render {} Props Void
    render dispatch {loaded} _ _ =
68 69 70 71 72 73 74 75 76 77 78 79 80
      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
                 }
          = maybe corpusInfoDefault identity loaded
81 82 83

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

84 85
getCorpus :: Int -> Aff (NodePoly CorpusInfo)
getCorpus = get <<< toUrl Back Corpus
86

87 88
corpusLoaderClass :: ReactClass (Loader.Props Int (NodePoly CorpusInfo))
corpusLoaderClass = createLoaderClass "CorpusLoader" getCorpus
89

90 91
corpusLoader :: Loader.Props Int (NodePoly CorpusInfo) -> ReactElement
corpusLoader = React.createLeafElement corpusLoaderClass