DocFocus.purs 2.65 KB
Newer Older
arturo's avatar
arturo committed
1 2 3 4 5 6
module Gargantext.Components.GraphExplorer.Frame.DocFocus
  ( docFocus
  ) where

import Gargantext.Prelude

7 8
import Data.Maybe (Maybe(..), isJust)
import Data.Tuple.Nested ((/\))
arturo's avatar
arturo committed
9 10 11
import Effect (Effect)
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (Elevation(..))
12 13 14
import Gargantext.Components.Document.API (loadData)
import Gargantext.Components.Document.Layout (layout)
import Gargantext.Components.Document.Types (LoadedData, DocPath)
arturo's avatar
arturo committed
15
import Gargantext.Components.GraphExplorer.Types (GraphSideDoc(..))
16 17 18 19
import Gargantext.Config.REST (logRESTError)
import Gargantext.Hooks.Loader (useLoaderEffect)
import Gargantext.Sessions (Session)
import Gargantext.Types (CTabNgramType(..), TabSubType(..), TabType(..))
arturo's avatar
arturo committed
20
import Gargantext.Utils.Reactix as R2
21
import Gargantext.Utils.Toestand as T2
arturo's avatar
arturo committed
22 23
import Reactix as R
import Reactix.DOM.HTML as H
24
import Toestand as T
arturo's avatar
arturo committed
25 26 27 28 29 30 31 32


here :: R2.Here
here = R2.here "Gargantext.Components.GraphExplorer.Frame.DocFocus"

type Props =
  ( graphSideDoc  :: GraphSideDoc
  , session       :: Session
arturo's avatar
arturo committed
33
  , closeCallback :: Unit -> Effect Unit
arturo's avatar
arturo committed
34 35
  )

36
docFocus :: R2.Leaf ( key :: String | Props )
arturo's avatar
arturo committed
37
docFocus = R2.leaf docFocusCpt
38
docFocusCpt :: R.Component ( key :: String | Props )
arturo's avatar
arturo committed
39 40 41
docFocusCpt = here.component "main" cpt where
  cpt { graphSideDoc: GraphSideDoc { docId, listId, corpusId }
      , session
arturo's avatar
arturo committed
42
      , closeCallback
arturo's avatar
arturo committed
43
      } _ = do
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 70 71 72
    -- | States
    -- |
    state' /\ state <- R2.useBox' (Nothing :: Maybe LoadedData)

    -- | Computed
    -- |
    let

      tabType :: TabType
      tabType = TabDocument (TabNgramType CTabTerms)

      path :: DocPath
      path =
        { listIds: [listId]
        , mCorpusId: Just corpusId
        , nodeId: docId
        , session
        , tabType
        }

    -- | Hooks
    -- |
    useLoaderEffect
      { errorHandler: logRESTError here "[docFocus]"
      , loader: loadData
      , path
      , state
      }

arturo's avatar
arturo committed
73 74 75 76
    -- | Render
    -- |
    pure $

77

arturo's avatar
arturo committed
78
      H.div
arturo's avatar
arturo committed
79
      { className: "graph-doc-focus" }
arturo's avatar
arturo committed
80
      [
81 82 83 84 85 86 87 88 89 90 91 92
        B.cloak
        { isDisplayed: isJust state'
        , idlingPhaseDuration: Just 150
        , cloakSlot:
            B.preloader
            {}

        , defaultSlot:
            R2.fromMaybe state' \loaded ->
              layout
              { loaded
              , path
93
              , session
94 95 96 97 98
              , sideControlsSlot: Just $
                  H.div
                  { className: "graph-doc-focus__header" }
                  [
                    B.iconButton
99
                    { name: "times"
100 101 102 103 104 105
                    , elevation: Level2
                    , callback: closeCallback
                    }
                  ]
              }
        }
arturo's avatar
arturo committed
106
      ]