Commit fe2bbca3 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[loader] rewrite params for useLoader

parent 034ea2e7
......@@ -331,7 +331,11 @@ pageLayoutCpt = here.component "pageLayout" cpt where
, totalRecords = count }
, localCategories
, params: paramsS } []
useLoader (path { params = paramsS' }) loader render
let errorHandler err = here.log2 "[pageLayout] RESTError" err
useLoader { errorHandler
, path: path { params = paramsS' }
, loader
, render }
type PageProps = (
documents :: Array DocumentsView
......
......@@ -34,7 +34,7 @@ import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(Search, NodeAPI))
import Gargantext.Routes as Routes
import Gargantext.Sessions (Session, sessionId, post, deleteWithBody)
import Gargantext.Types (NodeType(..), OrderBy(..), NodePath(..), NodeID)
import Gargantext.Types (NodeType(..), OrderBy(..), NodeID)
import Gargantext.Utils (toggleSet, zeroPad)
import Gargantext.Utils.Reactix as R2
......@@ -122,7 +122,6 @@ instance Eq Rows where
-- | Main layout of the Documents Tab of a Corpus
docView :: Record Props -> R.Element
docView props = R.createElement docViewCpt props []
docViewCpt :: R.Component Props
docViewCpt = here.component "docView" cpt
where
......@@ -172,7 +171,6 @@ togglePendingDeletion (_ /\ setDeletions) nid = setDeletions setter
docViewGraph :: Record Props -> R.Element
docViewGraph props = R.createElement docViewCpt props []
docViewGraphCpt :: R.Component Props
docViewGraphCpt = here.component "docViewGraph" cpt
where
......@@ -266,7 +264,6 @@ doc2view ( Document { id
contact2view :: Contact -> ContactsView
contact2view (Contact { c_id
, c_created: date
, c_hyperdata
, c_annuaireId
, c_score
......@@ -278,7 +275,8 @@ contact2view (Contact { c_id
, delete: false
}
err2view message =
err2view :: forall a. a -> DocumentsView
err2view _message =
DocumentsView { id: 1
, date: ""
, title : "SearchNoResult"
......@@ -307,15 +305,17 @@ type PageProps = ( rowsLoaded :: Rows | PageLayoutProps )
-- | Loads and renders a page
pageLayout :: R2.Component PageLayoutProps
pageLayout = R.createElement pageLayoutCpt
pageLayoutCpt :: R.Component PageLayoutProps
pageLayoutCpt = here.component "pageLayout" cpt
where
cpt { container, deletions, frontends, path, session, totalRecords } _ = do
path' <- T.useLive T.unequal path
useLoader path' loadPage $ \rowsLoaded ->
page { container, deletions, frontends, path, rowsLoaded, session, totalRecords } []
useLoader { errorHandler
, loader: loadPage
, path: path'
, render: \rowsLoaded -> page { container, deletions, frontends, path, rowsLoaded, session, totalRecords } [] }
errorHandler err = here.log2 "[pageLayout] RESTError" err
page :: R2.Component PageProps
page = R.createElement pageCpt
......@@ -330,12 +330,11 @@ pageCpt = here.component "page" cpt
, rowsLoaded
, session
, totalRecords } _ = do
path'@{ nodeId, listId, query } <- T.useLive T.unequal path
path' <- T.useLive T.unequal path
params <- T.useFocused (_.params) (\a b -> b { params = a }) path
deletions' <- T.useLive T.unequal deletions
let isChecked id = Set.member id deletions'.pending
isDeleted (DocumentsView {id}) = Set.member id deletions'.deleted
let isDeleted (DocumentsView {id}) = Set.member id deletions'.deleted
rows path' = case rowsLoaded of
Docs {docs} -> docRow path' <$> Seq.filter (not <<< isDeleted) docs
......@@ -362,17 +361,12 @@ pageCpt = here.component "page" cpt
documentUrl id { listId, nodeId } =
url frontends $ Routes.CorpusDocument (sessionId session) nodeId listId id
pairUrl (Pair {id,label})
| id > 1 = H.a { href, target: "blank" } [ H.text label ]
where href = url session $ NodePath (sessionId session) NodeContact (Just id)
| otherwise = H.text label
contactRow path' (ContactsView { id, hyperdata: HyperdataRowContact { firstname, lastname, labs }
, score, annuaireId, delete
, annuaireId, delete
}) =
{ row:
T.makeRow [ H.div {} [ H.a { className: gi Favorite, on: {click: markClick path'} } [] ]
, maybeStricken delete [ H.a {target: "_blank", href: contactUrl annuaireId id}
, maybeStricken delete [ H.a { target: "_blank", href: contactUrl id }
[ H.text $ firstname <> " " <> lastname ]
]
, maybeStricken delete [ H.text labs ]
......@@ -381,9 +375,9 @@ pageCpt = here.component "page" cpt
}
where
markClick { nodeId } _ = markCategory session nodeId Favorite [id]
contactUrl aId id' = url frontends $ Routes.ContactPage (sessionId session) annuaireId id'
contactUrl id' = url frontends $ Routes.ContactPage (sessionId session) annuaireId id'
docRow path' dv@(DocumentsView {id, score, title, source, authors, pairs, delete, category}) =
docRow path' dv@(DocumentsView {id, title, source, delete, category}) =
{ row:
T.makeRow [ H.div {} [ H.a { className: gi category, on: {click: markClick path'} } [] ]
, maybeStricken delete [ H.text $ publicationDate dv ]
......@@ -400,7 +394,7 @@ pageCpt = here.component "page" cpt
| otherwise = H.div {}
publicationDate :: DocumentsView -> String
publicationDate (DocumentsView {publication_year, publication_month, publication_day}) =
publicationDate (DocumentsView { publication_year, publication_month }) =
(zeroPad 2 publication_year) <> "-" <> (zeroPad 2 publication_month)
-- <> "-" <> (zeroPad 2 publication_day)
......
......@@ -59,15 +59,18 @@ data FolderStyle = FolderUp | FolderChild
folderView :: R2.Leaf Props
folderView props = R.createElement folderViewCpt props []
folderViewCpt :: R.Component Props
folderViewCpt = here.component "folderViewCpt" cpt where
cpt {nodeId, session, backFolder, tasks, reloadForest} _ = do
setPopoverRef <- R.useRef Nothing
reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
useLoader { nodeId, session, reload: reload'} loadFolders $
\folders -> folderViewMain {folders, nodeId, session, backFolder, tasks, reload, setPopoverRef, reloadForest}
useLoader { errorHandler
, loader: loadFolders
, path: { nodeId, session, reload: reload'}
, render: \folders -> folderViewMain {folders, nodeId, session, backFolder, tasks, reload, setPopoverRef, reloadForest} }
where
errorHandler err = here.log2 "[folderView] RESTError" err
type FolderViewProps =
(
......@@ -86,7 +89,14 @@ folderViewMain props = R.createElement folderViewMainCpt props []
folderViewMainCpt :: R.Component FolderViewProps
folderViewMainCpt = here.component "folderViewMainCpt" cpt where
cpt {nodeId, session, backFolder, tasks, setPopoverRef, reload, reloadForest, folders: tree@(NTree (LNode {parent_id: parentId, nodeType}) (folders))} _ = do
cpt { backFolder
, folders: NTree (LNode {parent_id: parentId, nodeType}) (folders)
, nodeId
, reload
, reloadForest
, session
, setPopoverRef
, tasks } _ = do
let foldersS = A.sortBy sortFolders folders
let backHome = isBackHome nodeType
let parent = makeParentFolder parentId session backFolder backHome
......
......@@ -80,11 +80,16 @@ treeLoaderCpt = here.component "treeLoader" cpt where
cpt p@{ root, session } _ = do
-- app <- T.useLive T.unequal p.reloadRoot
let fetch { root: r } = getNodeTree session r
useLoader { root } fetch loaded where
loaded tree' = tree props where
props = Record.merge common extra where
common = RecordE.pick p :: Record Common
extra = { tree: tree', reloadTree: p.reload, session }
useLoader { errorHandler
, loader: fetch
, path: { root }
, render: loaded }
where
loaded tree' = tree props where
props = Record.merge common extra where
common = RecordE.pick p :: Record Common
extra = { tree: tree', reloadTree: p.reload, session }
errorHandler err = here.log2 "[treeLoader] RESTError" err
getNodeTree :: Session -> ID -> Aff (Either RESTError FTree)
getNodeTree session nodeId = get session $ GR.NodeAPI GT.Tree (Just nodeId) ""
......@@ -185,8 +190,12 @@ childLoaderCpt = here.component "childLoader" cpt where
reload <- T.useBox T2.newReload
let reloads = [ reload, p.reloadRoot, p.reloadTree ]
cache <- (A.cons p.id) <$> traverse (T.useLive T.unequal) reloads
useLoader cache fetch (paint reload)
useLoader { errorHandler
, loader: fetch
, path: cache
, render: paint reload }
where
errorHandler err = here.log2 "[childLoader] RESTError" err
fetch _ = getNodeTreeFirstLevel p.session p.id
paint reload tree' = render (Record.merge base extra) where
base = nodeProps { reload = reload }
......
......@@ -307,22 +307,27 @@ nodeActionsCpt = here.component "nodeActions" cpt where
graphNodeActions :: R2.Leaf NodeActionsCommon
graphNodeActions props = R.createElement graphNodeActionsCpt props []
graphNodeActionsCpt :: R.Component NodeActionsCommon
graphNodeActionsCpt = here.component "graphNodeActions" cpt where
cpt { id, session, refresh } _ =
useLoader id (graphVersions session) $ \gv ->
nodeActionsGraph { graphVersions: gv, session, id, refresh } []
useLoader { errorHandler
, loader: graphVersions session
, path: id
, render: \gv -> nodeActionsGraph { graphVersions: gv, session, id, refresh } [] }
graphVersions session graphId = GraphAPI.graphVersions { graphId, session }
errorHandler err = here.log2 "[graphNodeActions] RESTError" err
listNodeActions :: R2.Leaf NodeActionsCommon
listNodeActions props = R.createElement listNodeActionsCpt props []
listNodeActionsCpt :: R.Component NodeActionsCommon
listNodeActionsCpt = here.component "listNodeActions" cpt where
cpt { id, session, refresh } _ =
useLoader { nodeId: id, session } loadCorpusWithChild $ \{ corpusId } ->
nodeActionsNodeList
{ listId: id, nodeId: corpusId, session, refresh: refresh
, nodeType: GT.TabNgramType GT.CTabTerms }
useLoader { errorHandler
, path: { nodeId: id, session }
, loader: loadCorpusWithChild
, render: \{ corpusId } -> nodeActionsNodeList
{ listId: id, nodeId: corpusId, session, refresh: refresh
, nodeType: GT.TabNgramType GT.CTabTerms } }
where
errorHandler err = here.log2 "[listNodeActions] RESTError" err
......@@ -6,6 +6,12 @@ import Data.Array as A
import Data.Either (Either)
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
import React.SyntheticEvent as E
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
import Toestand as T
import Gargantext.Components.Forest.Tree.Node.Action (Props, Action, subTreeOut, setTreeOut)
import Gargantext.Components.Forest.Tree.Node.Tools (nodeText)
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..))
......@@ -16,11 +22,6 @@ import Gargantext.Routes as GR
import Gargantext.Sessions (Session(..), get)
import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
import React.SyntheticEvent as E
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Tools.SubTree"
......@@ -55,17 +56,21 @@ subTreeViewCpt = here.component "subTreeView" cpt
-- (valAction /\ setAction) = action
-- _ <- pure $ setAction (const $ setTreeOut valAction Nothing)
useLoader session (loadSubTree showtypes) $
\tree ->
subTreeViewLoaded { action
, dispatch
, handed
, id
, nodeType
, session
, subTreeParams
, tree
} []
useLoader { errorHandler
, loader: loadSubTree showtypes
, path: session
, render: \tree ->
subTreeViewLoaded { action
, dispatch
, handed
, id
, nodeType
, session
, subTreeParams
, tree
} [] }
where
errorHandler err = here.log2 "RESTError" err
loadSubTree :: Array GT.NodeType -> Session -> Aff (Either RESTError FTree)
loadSubTree nodetypes session = getSubTree session treeId nodetypes
......
......@@ -69,8 +69,12 @@ explorerLayoutCpt = here.component "explorerLayout" cpt where
cpt props@{ boxes: { graphVersion }, graphId, session } _ = do
graphVersion' <- T.useLive T.unequal graphVersion
useLoader graphId (getNodes session graphVersion') handler
useLoader { errorHandler
, loader: getNodes session graphVersion'
, path: graphId
, render: handler }
where
errorHandler err = here.log2 "[explorerLayout] RESTError" err
handler loaded@(GET.HyperdataGraph { graph: hyperdataGraph }) =
explorerWriteGraph (Record.merge props { graph, hyperdataGraph: loaded, mMetaData' }) []
where
......
......@@ -28,11 +28,6 @@ import Data.Tuple (Tuple(..), fst)
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (Aff)
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
import Unsafe.Coerce (unsafeCoerce)
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Components.NgramsTable.Components as NTC
......@@ -42,7 +37,7 @@ import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as TT
import Gargantext.Components.Table.Types as TT
import Gargantext.Config.REST (RESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Loader (loader, useLoader)
import Gargantext.Routes (SessionRoute(..)) as R
import Gargantext.Sessions (Session, get)
import Gargantext.Types (CTabNgramType, OrderBy(..), SearchQuery, TabType, TermList(..), TermSize, termLists, termSizes)
......@@ -51,6 +46,10 @@ import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Seq as Seq
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
import Unsafe.Coerce (unsafeCoerce)
here :: R2.Here
here = R2.here "Gargantext.Components.NgramsTable"
......@@ -579,7 +578,12 @@ mainNgramsTableCpt = here.component "mainNgramsTable" cpt
, tasks
, versionedWithCount
, withAutoUpdate } []
useLoader path' loader render
useLoader { errorHandler
, loader
, path: path'
, render }
errorHandler err = here.log2 "[mainNgramsTable] RESTError" err
-- NOTE With cache on
-- versionEndpoint :: Record MainNgramsTableProps -> PageParams -> Aff Version
......
......@@ -79,8 +79,12 @@ annuaireLayoutWithKeyCpt = here.component "annuaireLayoutWithKey" cpt where
path <- T.useBox nodeId
path' <- T.useLive T.unequal path
useLoader path' (getAnnuaireInfo session) $
\info -> annuaire { frontends, info, path, session }
useLoader { errorHandler
, loader: getAnnuaireInfo session
, path: path'
, render: \info -> annuaire { frontends, info, path, session } }
where
errorHandler err = here.log2 "[annuaireLayoutWithKey] RESTError" err
type AnnuaireProps =
( session :: Session
......@@ -142,8 +146,12 @@ pageLayoutCpt = here.component "pageLayout" cpt
cpt { frontends, pagePath, session } _ = do
pagePath' <- T.useLive T.unequal pagePath
useLoader pagePath' (loadPage session) $
\table -> page { session, table, frontends, pagePath }
useLoader { errorHandler
, loader: loadPage session
, path: pagePath'
, render: \table -> page { session, table, frontends, pagePath } }
where
errorHandler err = here.log2 "[pageLayout] RESTError" err
type PageProps =
( session :: Session
......
......@@ -4,22 +4,18 @@ module Gargantext.Components.Nodes.Annuaire.User
)
where
import Data.Either (Either(..))
import Gargantext.Prelude
import Data.Either (Either)
import Data.Lens as L
import Data.Maybe (Maybe(..), fromMaybe)
import Effect (Effect)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Prelude
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (Contact(..), ContactData, ContactTouch(..), ContactWhere(..), ContactWho(..), HyperdataContact(..), HyperdataUser(..), _city, _country, _firstName, _labTeamDeptsJoinComma, _lastName, _mail, _office, _organizationJoinComma, _ouFirst, _phone, _role, _shared, _touch, _who, defaultContactTouch, defaultContactWhere, defaultContactWho, defaultHyperdataContact, defaultHyperdataUser)
import Gargantext.Components.Nodes.Annuaire.Tabs as Tabs
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (Contact(..), ContactData, ContactTouch(..), ContactWhere(..), ContactWho(..), HyperdataContact(..), HyperdataUser(..), _city, _country, _firstName, _labTeamDeptsJoinComma, _lastName, _mail, _office, _organizationJoinComma, _ouFirst, _phone, _role, _shared, _touch, _who, defaultContactTouch, defaultContactWhere, defaultContactWho, defaultHyperdataContact, defaultHyperdataUser)
import Gargantext.Components.Nodes.Lists.Types as LT
import Gargantext.Components.Nodes.Texts.Types as TT
import Gargantext.Config.REST (RESTError)
......@@ -30,6 +26,9 @@ import Gargantext.Sessions (WithSession, WithSessionContext, Session, get, put,
import Gargantext.Types (NodeType(..), SidePanelState)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Annuaire.User"
......@@ -217,25 +216,29 @@ userLayoutWithKeyCpt = here.component "userLayoutWithKey" cpt
cacheState <- T.useBox LT.CacheOn
useLoader {nodeId, reload: reload', session} getUserWithReload $
\contactData@{contactNode: Contact {name, hyperdata}} ->
H.ul { className: "col-md-12 list-group" } [
display { title: fromMaybe "no name" name }
(contactInfos hyperdata (onUpdateHyperdata reload))
, Tabs.tabs {
cacheState
, contactData
, frontends
, nodeId
, reloadForest
, reloadRoot
, session
, sidePanel
, sidePanelState
, tasks
}
]
useLoader { errorHandler
, loader: getUserWithReload
, path: { nodeId, reload: reload', session }
, render: \contactData@{contactNode: Contact {name, hyperdata}} ->
H.ul { className: "col-md-12 list-group" } [
display { title: fromMaybe "no name" name }
(contactInfos hyperdata (onUpdateHyperdata reload))
, Tabs.tabs {
cacheState
, contactData
, frontends
, nodeId
, reloadForest
, reloadRoot
, session
, sidePanel
, sidePanelState
, tasks
}
]
}
where
errorHandler err = here.log2 "[userLayoutWithKey] RESTError" err
onUpdateHyperdata :: T2.ReloadS -> HyperdataUser -> Effect Unit
onUpdateHyperdata reload hd = do
launchAff_ $ do
......
......@@ -195,7 +195,6 @@ contactLayoutCpt = here.component "contactLayout" cpt where
contactLayoutWithKey :: R2.Leaf AnnuaireKeyLayoutProps
contactLayoutWithKey props = R.createElement contactLayoutWithKeyCpt props []
contactLayoutWithKeyCpt :: R.Component AnnuaireKeyLayoutProps
contactLayoutWithKeyCpt = here.component "contactLayoutWithKey" cpt where
cpt { annuaireId
......@@ -210,23 +209,26 @@ contactLayoutWithKeyCpt = here.component "contactLayoutWithKey" cpt where
reload <- T.useBox T2.newReload
_ <- T.useLive T.unequal reload
cacheState <- T.useBox LT.CacheOn
useLoader nodeId (getAnnuaireContact session annuaireId) $
\contactData@{contactNode: Contact' {name, hyperdata}} ->
H.ul { className: "col-md-12 list-group" }
[ display { title: fromMaybe "no name" name }
(contactInfos hyperdata (onUpdateHyperdata reload))
, Tabs.tabs
{ cacheState
, contactData
, frontends
, nodeId
, session
, sidePanel
, sidePanelState
, reloadForest
, reloadRoot
, tasks } ]
useLoader { errorHandler
, loader: getAnnuaireContact session annuaireId
, path: nodeId
, render: \contactData@{contactNode: Contact' {name, hyperdata}} ->
H.ul { className: "col-md-12 list-group" }
[ display { title: fromMaybe "no name" name }
(contactInfos hyperdata (onUpdateHyperdata reload))
, Tabs.tabs
{ cacheState
, contactData
, frontends
, nodeId
, session
, sidePanel
, sidePanelState
, reloadForest
, reloadRoot
, tasks } ] }
where
errorHandler err = here.log2 "[contactLayoutWithKey] RESTError" err
onUpdateHyperdata :: T2.ReloadS -> HyperdataContact -> Effect Unit
onUpdateHyperdata reload hd =
launchAff_ $
......
......@@ -114,8 +114,12 @@ corpusLayoutWithKeyCpt = here.component "corpusLayoutWithKey" cpt where
cpt { nodeId, session } _ = do
reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
useLoader { nodeId, reload: reload', session } loadCorpusWithReload $
\corpus -> corpusLayoutView { corpus, nodeId, reload, session }
useLoader { errorHandler
, loader: loadCorpusWithReload
, path: { nodeId, reload: reload', session }
, render: \corpus -> corpusLayoutView { corpus, nodeId, reload, session } }
where
errorHandler err = here.log2 "[corpusLayoutWithKey] RESTError" err
type ViewProps =
( corpus :: NodePoly Hyperdata
......
......@@ -37,8 +37,12 @@ metricsLoadViewCpt = here.component "metricsLoadView" cpt
cpt { getMetrics, loaded, path, reload, session, onClick, onInit } _ = do
reload' <- T.useLive T.unequal reload
useLoader (reload' /\ path) (getMetrics session) $ \l ->
loaded { path, reload, session, onClick, onInit } l
useLoader { errorHandler
, loader: getMetrics session
, path: reload' /\ path
, render: \l -> loaded { path, reload, session, onClick, onInit } l }
where
errorHandler err = here.log2 "RESTError" err
type MetricsWithCacheLoadViewProps res ret = (
getMetricsHash :: Session -> ReloadPath -> Aff (Either RESTError Hash)
......
......@@ -52,17 +52,20 @@ dashboardLayoutWithKeyCpt = here.component "dashboardLayoutWithKey" cpt
reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
useLoader {nodeId, reload: reload', session} DT.loadDashboardWithReload $
\(DT.DashboardData { hyperdata: DT.Hyperdata h, parentId }) -> do
let { charts, fields } = h
dashboardLayoutLoaded { charts
, corpusId: parentId
, defaultListId: 0
, fields
, nodeId
, onChange: onChange nodeId reload (DT.Hyperdata h)
, session } []
useLoader { errorHandler
, loader: DT.loadDashboardWithReload
, path: { nodeId, reload: reload', session }
, render: \(DT.DashboardData { hyperdata: DT.Hyperdata h, parentId }) -> do
let { charts, fields } = h
dashboardLayoutLoaded { charts
, corpusId: parentId
, defaultListId: 0
, fields
, nodeId
, onChange: onChange nodeId reload (DT.Hyperdata h)
, session } [] }
where
errorHandler err = here.log2 "[dashboardLayoutWithKey] RESTError" err
onChange :: NodeID -> T2.ReloadS -> DT.Hyperdata -> { charts :: Array P.PredefinedChart
, fields :: FTFieldList } -> Effect Unit
onChange nodeId' reload (DT.Hyperdata h) { charts, fields } = do
......
......@@ -150,11 +150,14 @@ documentLayoutWithKeyCpt :: R.Component KeyLayoutProps
documentLayoutWithKeyCpt = here.component "documentLayoutWithKey" cpt
where
cpt { listId, mCorpusId, nodeId, session } _ = do
useLoader path loadData $ \loaded ->
docViewWrapper { loaded, path } []
useLoader { errorHandler
, loader: loadData
, path
, render: \loaded -> docViewWrapper { loaded, path } [] }
where
tabType = TabDocument (TabNgramType CTabTerms)
path = { listIds: [listId], mCorpusId, nodeId, session, tabType }
errorHandler err = here.log2 "[documentLayoutWithKey] RESTError" err
------------------------------------------------------------------------
......
......@@ -55,8 +55,12 @@ fileLayout props = R.createElement fileLayoutCpt props []
fileLayoutCpt :: R.Component FileLayoutProps
fileLayoutCpt = here.component "fileLayout" cpt where
cpt { nodeId, session } _ = do
useLoader nodeId (loadFile session) onLoad
useLoader { errorHandler
, loader: loadFile session
, path: nodeId
, render: onLoad }
where
errorHandler err = here.log2 "RESTError" err
onLoad loaded = fileLayoutLoaded { loaded, nodeId, session }
loadFile :: Session -> NodeID -> Aff (Either RESTError File)
......
......@@ -66,8 +66,12 @@ frameLayoutWithKeyCpt = here.component "frameLayoutWithKey" cpt where
cpt { nodeId, session, nodeType} _ = do
reload <- T.useBox T2.newReload
reload' <- T.useLive T.unequal reload
useLoader {nodeId, reload: reload', session} loadframeWithReload $
\frame -> frameLayoutView {frame, nodeId, reload, session, nodeType}
useLoader { errorHandler
, loader: loadframeWithReload
, path: {nodeId, reload: reload', session}
, render: \frame -> frameLayoutView {frame, nodeId, reload, session, nodeType} }
where
errorHandler err = here.log2 "[frameLayoutWithKey] RESTError" err
type ViewProps =
( frame :: NodePoly Hyperdata
......
......@@ -73,8 +73,13 @@ renderPublic props = R.createElement renderPublicCpt props []
renderPublicCpt :: R.Component ()
renderPublicCpt = here.component "renderPublic" cpt where
cpt _ _ = do
useLoader { reload: 0 } loadPublicData loaded where
loaded publicData = publicLayout { publicData }
useLoader { errorHandler
, loader: loadPublicData
, path: { reload: 0 }
, render: loaded }
where
loaded publicData = publicLayout { publicData }
errorHandler err = here.log2 "RESTError" err
publicLayout :: Record PublicDataProps -> R.Element
publicLayout props = R.createElement publicLayoutCpt props []
......
module Gargantext.Components.Nodes.Lists where
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe)
import Effect (Effect)
import Effect.Aff (launchAff_)
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
import Toestand as T
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.NgramsTable.Loader (clearCache)
import Gargantext.Components.Node (NodePoly(..))
......@@ -12,15 +17,11 @@ import Gargantext.Components.Nodes.Lists.Tabs as Tabs
import Gargantext.Components.Nodes.Lists.Types (CacheState(..), SidePanel)
import Gargantext.Components.Table as Table
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude (Unit, bind, const, discard, pure, show, unit, ($), (<>))
import Gargantext.Prelude
import Gargantext.Sessions (WithSession, WithSessionContext, Session, sessionId, getCacheState, setCacheState)
import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Lists"
......@@ -56,7 +57,6 @@ type KeyProps = ( key :: String | Props )
listsLayoutWithKey :: R2.Component KeyProps
listsLayoutWithKey = R.createElement listsLayoutWithKeyCpt
listsLayoutWithKeyCpt :: R.Component KeyProps
listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where
cpt { nodeId
......@@ -65,11 +65,9 @@ listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where
, reloadRoot
, session
, sessionUpdate
, sidePanel
, sidePanelState
, tasks } _ = do
activeTab <- T.useBox 0
reloadMainPage' <- T.useLive T.unequal reloadMainPage
_reloadMainPage' <- T.useLive T.unequal reloadMainPage
let path = { nodeId, session }
......@@ -79,40 +77,42 @@ listsLayoutWithKeyCpt = here.component "listsLayoutWithKey" cpt where
R.useEffectOnce' $ do
T.listen (\{ new } -> afterCacheStateChange new) cacheState
useLoader path loadCorpusWithChild $
\corpusData@{ corpusId, corpusNode: NodePoly poly, defaultListId } ->
let { date, hyperdata : Hyperdata h, name } = poly
CorpusInfo { authors, desc, query } = getCorpusInfo h.fields
in
R.fragment [
Table.tableHeaderLayout {
cacheState
, date
, desc
, key: "listsLayoutWithKey-header-" <> (show cacheState')
, query
, title: "Corpus " <> name
, user: authors } []
, Tabs.tabs {
activeTab
, cacheState
, corpusData
, corpusId
, key: "listsLayoutWithKey-tabs-" <> (show cacheState')
, reloadForest
, reloadRoot
, session
, tasks
}
]
useLoader { errorHandler
, path
, loader: loadCorpusWithChild
, render: \corpusData@{ corpusId, corpusNode: NodePoly poly } ->
let { date, hyperdata : Hyperdata h, name } = poly
CorpusInfo { authors, desc, query } = getCorpusInfo h.fields
in
R.fragment [
Table.tableHeaderLayout {
cacheState
, date
, desc
, key: "listsLayoutWithKey-header-" <> (show cacheState')
, query
, title: "Corpus " <> name
, user: authors } []
, Tabs.tabs {
activeTab
, cacheState
, corpusData
, corpusId
, key: "listsLayoutWithKey-tabs-" <> (show cacheState')
, reloadForest
, reloadRoot
, session
, tasks
}
] }
where
errorHandler err = here.log2 "[listsLayoutWithKey] RESTError" err
afterCacheStateChange cacheState = do
launchAff_ $ clearCache unit
sessionUpdate $ setCacheState session nodeId cacheState
type SidePanelProps =
( session :: Session
, sidePanel :: T.Box (Maybe (Record SidePanel))
, sidePanelState :: T.Box GT.SidePanelState
)
......@@ -123,7 +123,6 @@ sidePanelCpt :: R.Component SidePanelProps
sidePanelCpt = here.component "sidePanel" cpt
where
cpt { session
, sidePanel
, sidePanelState } _ = do
sidePanelState' <- T.useLive T.unequal sidePanelState
......@@ -151,6 +150,6 @@ sidePanelDocView = R.createElement sidePanelDocViewCpt
sidePanelDocViewCpt :: R.Component SidePanelDocView
sidePanelDocViewCpt = here.component "sidePanelDocView" cpt where
cpt { session } _ = do
cpt { } _ = do
-- pure $ H.h4 {} [ H.text txt ]
pure $ H.div {} [ H.text "Hello ngrams" ]
......@@ -7,6 +7,10 @@ import Data.Maybe (Maybe(..))
import Data.Show.Generic (genericShow)
import Data.Tuple.Nested ((/\))
import Effect.Aff (launchAff_)
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Components.Charts.Options.ECharts (dispatchAction)
import Gargantext.Components.Charts.Options.Type (EChartsInstance, EChartActionData)
import Gargantext.Components.DocsTable as DT
......@@ -26,9 +30,6 @@ import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (WithSession, Session, getCacheState)
import Gargantext.Types (CTabNgramType(..), ListId, NodeID, SidePanelState(..), TabSubType(..), TabType(..))
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Texts"
......@@ -75,7 +76,6 @@ type KeyProps = (
textsLayoutWithKey :: R2.Component KeyProps
textsLayoutWithKey = R.createElement textsLayoutWithKeyCpt
textsLayoutWithKeyCpt :: R.Component KeyProps
textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt
where
......@@ -90,32 +90,35 @@ textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt
R.useEffectOnce' $ do
T.listen (\{ new } -> afterCacheStateChange new) cacheState
useLoader { nodeId, session } loadCorpusWithChild $
\corpusData@{ corpusId, corpusNode, defaultListId } -> do
let NodePoly { date, hyperdata: Hyperdata h, name } = corpusNode
CorpusInfo { authors, desc, query } = getCorpusInfo h.fields
title = "Corpus " <> name
R.fragment
[ Table.tableHeaderLayout { cacheState
, date
, desc
, query
, title
, user: authors
, key: "textsLayoutWithKey-" <> (show cacheState') } []
, tabs { cacheState
, corpusData
, corpusId
, frontends
, session
, sidePanel
, sidePanelState
, yearFilter
, eChartsInstance
}
]
useLoader { errorHandler
, loader: loadCorpusWithChild
, path: { nodeId, session }
, render: \corpusData@{ corpusId, corpusNode } -> do
let NodePoly { date, hyperdata: Hyperdata h, name } = corpusNode
CorpusInfo { authors, desc, query } = getCorpusInfo h.fields
title = "Corpus " <> name
R.fragment
[ Table.tableHeaderLayout { cacheState
, date
, desc
, query
, title
, user: authors
, key: "textsLayoutWithKey-" <> (show cacheState') } []
, tabs { cacheState
, corpusData
, corpusId
, frontends
, session
, sidePanel
, sidePanelState
, yearFilter
, eChartsInstance
}
] }
where
errorHandler err = here.log2 "[textsLayoutWithKey] RESTError" err
afterCacheStateChange cacheState = do
launchAff_ $ clearCache unit
-- TODO
......@@ -139,21 +142,28 @@ type TabsProps =
( cacheState :: T.Box LT.CacheState
, corpusData :: CorpusData
, corpusId :: NodeID
, eChartsInstance :: T.Box (Maybe EChartsInstance)
, frontends :: Frontends
, session :: Session
, sidePanel :: T.Box (Maybe (Record TT.SidePanel))
, sidePanelState :: T.Box SidePanelState
, yearFilter :: T.Box (Maybe Year)
, eChartsInstance :: T.Box (Maybe EChartsInstance)
)
tabs :: Record TabsProps -> R.Element
tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component TabsProps
tabsCpt = here.component "tabs" cpt
where
cpt { cacheState, corpusId, corpusData, frontends, session, sidePanel, sidePanelState, yearFilter, eChartsInstance } _ = do
cpt { cacheState
, corpusId
, corpusData
, eChartsInstance
, frontends
, session
, sidePanel
, sidePanelState
, yearFilter } _ = do
let
path = initialPath
......@@ -344,9 +354,9 @@ docViewLayoutRec { cacheState
, frontends
, listId
, session
, tabType
, sidePanel
, sidePanelState
, tabType
, yearFilter
} =
{ cacheState
......
......@@ -227,7 +227,6 @@ openedSidePanelCpt = here.component "openedSidePanel" cpt where
, route
, sidePanelGraph
, sidePanelState
, sidePanelLists
, sidePanelTexts }
, session} _ = do
{ mGraph, mMetaData, removedNodeIds, selectedNodeIds, sideTab } <- GEST.focusedSidePanel sidePanelGraph
......@@ -241,7 +240,6 @@ openedSidePanelCpt = here.component "openedSidePanel" cpt where
GR.Lists _s _n -> do
pure $ wrapper
[ Lists.sidePanel { session
, sidePanel: sidePanelLists
, sidePanelState } [] ]
GR.PGraphExplorer _s g -> do
case (mGraph' /\ mGraphMetaData') of
......
module Gargantext.Hooks.Loader where
import Gargantext.Prelude
import Control.Bind ((=<<))
import Control.Monad.RWS (state)
import Data.Either (Either(..))
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..), isJust, maybe)
import Data.Newtype (class Newtype)
import Effect (Effect)
import Effect.Aff (Aff, launchAff_, throwError)
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Reactix as R
import Record as Record
import Simple.JSON as JSON
import Toestand as T
import Gargantext.Components.LoadingSpinner (loadingSpinner)
import Gargantext.Config.REST (RESTError)
import Gargantext.Prelude
import Gargantext.Utils.Crypto (Hash)
import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.Crypto (Hash)
import Gargantext.Utils.Reactix as R2
here :: R2.Here
......@@ -27,16 +32,20 @@ cacheName = "cache-api-loader"
clearCache :: Unit -> Aff Unit
clearCache _ = GUC.delete $ GUC.CacheName cacheName
type UseLoader path state =
( errorHandler :: RESTError -> Effect Unit
, loader :: path -> Aff (Either RESTError state)
, path :: path
, render :: state -> R.Element
)
useLoader :: forall path st. Eq path => Eq st
=> path
-> (path -> Aff (Either RESTError st))
-> (st -> R.Element)
=> Record (UseLoader path st)
-> R.Hooks R.Element
useLoader path loader' render = do
useLoader { errorHandler, loader: loader', path, render } = do
state <- T.useBox Nothing
useLoaderEffect path state loader'
useLoaderEffect { errorHandler, loader: loader', path, state: state }
pure $ loader { path, render, state } []
......@@ -48,22 +57,25 @@ type LoaderProps path st =
loader :: forall path st. Eq path => Eq st => R2.Component (LoaderProps path st)
loader = R.createElement loaderCpt
loaderCpt :: forall path st. Eq path => Eq st => R.Component (LoaderProps path st)
loaderCpt = here.component "loader" cpt
where
cpt { path, render, state } _ = do
cpt { render, state } _ = do
state' <- T.useLive T.unequal state
pure $ maybe (loadingSpinner {}) render state'
type UseLoaderEffect path state =
( errorHandler :: RESTError -> Effect Unit
, loader :: path -> Aff (Either RESTError state)
, path :: path
, state :: T.Box (Maybe state)
)
useLoaderEffect :: forall st path. Eq path => Eq st =>
path
-> T.Box (Maybe st)
-> (path -> Aff (Either RESTError st))
useLoaderEffect :: forall st path. Eq path => Eq st
=> Record (UseLoaderEffect path st)
-> R.Hooks Unit
useLoaderEffect path state loader = do
useLoaderEffect { errorHandler, loader: loader', path, state } = do
state' <- T.useLive T.unequal state
oPath <- R.useRef path
......@@ -74,9 +86,9 @@ useLoaderEffect path state loader = do
else do
R.setRef oPath path
R2.affEffect "G.H.Loader.useLoaderEffect" $ do
l <- loader path
l <- loader' path
case l of
Left _err -> throwError $ error "[useLoaderEffect] RESTError"
Left err -> liftEffect $ errorHandler err
Right l' -> liftEffect $ T.write_ (Just l') state
......@@ -141,7 +153,7 @@ useCachedAPILoaderEffect { cacheEndpoint
launchAff_ $ do
cache <- GUC.openCache $ GUC.CacheName cacheName
-- TODO Parallelize?
hr@(HashedResponse { hash, value }) <- GUC.cachedJson cache req
hr@(HashedResponse { hash }) <- GUC.cachedJson cache req
cacheReal <- cacheEndpoint path
case cacheReal of
Left _err -> throwError $ error $ "[useCachedAPILoaderEffect] RESTError"
......
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