Loader: the inner-component is now only mounted when data is loaded (no Maybe)

parent d1c7c8d9
......@@ -12,16 +12,18 @@ import Thermite (Render, PerformAction, simpleSpec, modifyState_, createReactSpe
data Action path = ForceReload | SetPath path
type InnerProps path loaded =
{ path :: path
, loaded :: Maybe loaded
type InnerPropsRow path loaded row =
( path :: path
, loaded :: loaded
, dispatch :: Action path -> Effect Unit
, children :: Children
}
| row
)
type InnerProps path loaded row = Record (InnerPropsRow path loaded row)
type PropsRow path loaded row =
( path :: path
, component :: ReactClass (InnerProps path loaded)
, component :: ReactClass (InnerProps path loaded (children :: Children))
| row
)
......@@ -68,7 +70,10 @@ createLoaderClass name loader =
createLoaderClass' name loader render
where
render :: Render (State path loaded) (Props' path loaded) (Action path)
render dispatch {component} {currentPath, loaded} c =
render _ _ {loaded: Nothing} _ =
-- TODO load spinner
[]
render dispatch {component} {currentPath, loaded: Just loaded} c =
[React.createElement component {path: currentPath, loaded, dispatch} c]
{-
......
......@@ -25,10 +25,7 @@ import Gargantext.Config.REST (get)
import Gargantext.Pages.Annuaire.User.Contacts.Types (Contact(..), HyperData(..))
------------------------------------------------------------------------------
type Props =
{ path :: Int
, loaded :: Maybe AnnuaireInfo
, dispatch :: Loader.Action Int -> Effect Unit }
type Props = Loader.InnerProps Int AnnuaireInfo ()
data Action
= TabsA Tab.Action
......@@ -82,8 +79,7 @@ loadedAnnuaireSpec :: Spec {} Props Void
loadedAnnuaireSpec = simpleSpec defaultPerformAction render
where
render :: Render {} Props Void
render _ {loaded: Nothing} _ _ = []
render _ {path: nodeId, loaded: Just (annuaireInfo@AnnuaireInfo {name, date})} _ _ =
render _ {path: nodeId, loaded: annuaireInfo@AnnuaireInfo {name, date}} _ _ =
T.renderTableHeaderLayout
{ title: name
, desc: name
......
......@@ -3,7 +3,7 @@ module Gargantext.Pages.Corpus where
import Data.Either (Either(..))
import Data.Lens (Lens', Prism', lens, prism)
import Data.Maybe (Maybe(..),maybe)
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
import React as React
import React (ReactClass, ReactElement)
......@@ -17,7 +17,7 @@ import Gargantext.Components.Loader (createLoaderClass)
import Gargantext.Components.Table as Table
import Gargantext.Config (toUrl, NodeType(..), End(..))
import Gargantext.Config.REST (get)
import Gargantext.Pages.Corpus.Tabs.Types (CorpusInfo(..), corpusInfoDefault)
import Gargantext.Pages.Corpus.Tabs.Types (CorpusInfo(..))
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
......@@ -77,7 +77,7 @@ corpusHeaderSpec = simpleSpec defaultPerformAction render
, date: date'
, hyperdata : CorpusInfo corpus
}
= maybe corpusInfoDefault identity loaded
= loaded
------------------------------------------------------------------------
......
......@@ -221,16 +221,16 @@ loadPage {nodeId, params: {limit, offset, orderBy}} = do
convOrderBy _ = DateAsc -- TODO
type PageLoaderProps ext =
type PageLoaderProps row =
{ path :: PageParams
, corpusInfo :: Maybe (NodePoly CorpusInfo)
, corpusInfo :: NodePoly CorpusInfo
, dispatch :: Action -> Effect Unit
| ext
| row
}
renderPage :: forall props path.
Render (Loader.State {nodeId :: Int | path} (Array DocumentsView))
{ corpusInfo :: Maybe (NodePoly CorpusInfo)
{ corpusInfo :: NodePoly CorpusInfo
, dispatch :: Action -> Effect Unit
| props
}
......@@ -254,7 +254,7 @@ renderPage loaderDispatch {corpusInfo, dispatch} {currentPath: {nodeId}, loaded:
((\(NodePoly n) -> n.hyperdata)
>>>
(\(CorpusInfo c) -> c.totalRecords)
<$> corpusInfo)
<$> Just corpusInfo) -- TODO
}
]
where
......
......@@ -54,10 +54,7 @@ type Props = { mode :: Mode | PropsRow }
type PageParams = {nodeId :: Int, params :: T.Params, mode :: Mode}
type Props' = { path :: PageParams
, loaded :: Maybe NgramsTable
, dispatch :: Loader.Action PageParams -> Effect Unit
}
type Props' = Loader.InnerProps PageParams NgramsTable ()
type NgramsTerm = String
......@@ -451,10 +448,7 @@ ngramsTableSpec' = simpleSpec performAction render
}
]
where
ngramsTable =
case applyNgramsTablePatch ngramsTablePatch <$> initTable of
Nothing -> NgramsTable mempty
Just t -> t
ngramsTable = applyNgramsTablePatch ngramsTablePatch initTable
rows = convertRow <$> Map.toUnfoldable (Map.filter displayRow (ngramsTable ^. _NgramsTable))
isRoot (NgramsElement e) = e.parent == Nothing
-- TODO: There is a missing case where we display a row that we should not.
......
......@@ -2,7 +2,6 @@ module Gargantext.Pages.Corpus.Tabs.Types where
import Data.Argonaut (class DecodeJson, decodeJson, (.?), (.??))
import Data.Maybe (Maybe(..))
import Effect (Effect)
--------------------------------------------------------
import Gargantext.Prelude
import Gargantext.Components.Node (NodePoly(..))
......@@ -45,11 +44,7 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where
pure $ CorpusInfo {title, desc, query, authors, chart, totalRecords}
-- TODO type Props = {nodeId :: Int, info :: Maybe (NodePoly CorpusInfo) }
type PropsRow =
( path :: Int
, loaded :: Maybe (NodePoly CorpusInfo)
, dispatch :: Loader.Action Int -> Effect Unit
)
type PropsRow = Loader.InnerPropsRow Int (NodePoly CorpusInfo) ()
type Props = Record PropsRow
-- TODO include Gargantext.Pages.Corpus.Tabs.States
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment