Corpus.purs 1.51 KB
Newer Older
1
module Gargantext.Components.Nodes.Corpus where
2

arturo's avatar
arturo committed
3 4 5 6 7 8 9 10 11 12 13
import Gargantext.Prelude

import Data.Maybe (Maybe(..), isJust)
import Data.Tuple.Nested ((/\))
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Corpus.Layout (layout)
import Gargantext.Components.GraphQL.Endpoints (getNode)
import Gargantext.Config.REST (logRESTError)
import Gargantext.Hooks.Loader (useLoaderEffect)
import Gargantext.Hooks.Session (useSession)
import Gargantext.Types (ID)
14
import Gargantext.Utils.Reactix as R2
15
import Reactix as R
16

17
type Props =
arturo's avatar
arturo committed
18
  ( nodeId  :: ID
19 20
  )

arturo's avatar
arturo committed
21 22
here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus"
Karen Konou's avatar
Karen Konou committed
23

arturo's avatar
arturo committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
node :: R2.Leaf ( key :: String | Props )
node = R2.leaf nodeCpt
nodeCpt :: R.Component ( key :: String | Props )
nodeCpt = here.component "node" cpt where
  cpt { nodeId } _ = do
    -- | States
    -- |
    session <- useSession

    state' /\ state <- R2.useBox' Nothing

    -- | Computed
    -- |
    let
      errorHandler = logRESTError here "[corpusLayout]"

      loader { nodeId: nodeId_, session: session_ } = getNode session_ nodeId_

    -- | Hooks
    -- |
    useLoaderEffect
      { errorHandler
      , loader
      , path: { nodeId, session }
      , state
      }

    -- | Render
    -- |
    pure $

      B.cloak
      { isDisplayed: isJust state'
      , idlingPhaseDuration: Just 150
      , cloakSlot:
          B.preloader
          {}

      , defaultSlot:
          R2.fromMaybe state' \nodeData ->

            layout
            { nodeId
            , nodeData
            }
      }