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