Commit 995d409a authored by James Laver's avatar James Laver

minor refactor of DocsTable. instead of reloading endlessly, we now rerender...

minor refactor of DocsTable. instead of reloading endlessly, we now rerender endlessly, which is easier to handle
parent 7ad9be28
...@@ -30,7 +30,7 @@ import Gargantext.Routes (AppRoute(..)) ...@@ -30,7 +30,7 @@ import Gargantext.Routes (AppRoute(..))
import Gargantext.Hooks.Router (useHashRouter) import Gargantext.Hooks.Router (useHashRouter)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Sessions as Sessions import Gargantext.Sessions as Sessions
import Gargantext.Sessions (Sessions, useSessions, unSessions) import Gargantext.Sessions (Sessions, useSessions)
-- TODO (what does this mean?) -- TODO (what does this mean?)
-- tree changes endConfig state => trigger endConfig change in outerLayout, layoutFooter etc -- tree changes endConfig state => trigger endConfig change in outerLayout, layoutFooter etc
......
...@@ -39,7 +39,7 @@ import Gargantext.Types (NodeType(..), OrderBy(..), TabType, TabPostQuery(..)) ...@@ -39,7 +39,7 @@ import Gargantext.Types (NodeType(..), OrderBy(..), TabType, TabPostQuery(..))
type NodeID = Int type NodeID = Int
type TotalRecords = Int type TotalRecords = Int
type Props = type LayoutProps =
( nodeId :: Int ( nodeId :: Int
, totalRecords :: Int , totalRecords :: Int
, chart :: R.Element , chart :: R.Element
...@@ -51,14 +51,15 @@ type Props = ...@@ -51,14 +51,15 @@ type Props =
-- ^ tabType is not ideal here since it is too much entangled with tabs and -- ^ tabType is not ideal here since it is too much entangled with tabs and
-- ngramtable. Let's see how this evolves. ) -- ngramtable. Let's see how this evolves. )
type PageLoaderProps = type PageLayoutProps =
( nodeId :: Int ( nodeId :: Int
, totalRecords :: Int , totalRecords :: Int
, tabType :: TabType , tabType :: TabType
, listId :: Int , listId :: Int
, corpusId :: Maybe Int , corpusId :: Maybe Int
, query :: Query , query :: Query
, session :: Session ) , session :: Session
, params :: R.State T.Params )
type LocalCategories = Map Int Category type LocalCategories = Map Int Category
type Query = String type Query = String
...@@ -121,34 +122,41 @@ instance decodeResponse :: DecodeJson Response where ...@@ -121,34 +122,41 @@ instance decodeResponse :: DecodeJson Response where
pure $ Response { cid, category: decodeCategory favorite, ngramCount, hyperdata } pure $ Response { cid, category: decodeCategory favorite, ngramCount, hyperdata }
docViewLayout :: Record LayoutProps -> R.Element
docViewLayout props = R.createElement docViewLayoutCpt props []
docViewLayoutCpt :: R.Component LayoutProps
docViewLayoutCpt = R.hooksComponent "G.C.DocsTable.docViewLayout" cpt
where
cpt layout _children = do
query <- R.useState' ""
params <- R.useState' T.initialParams
pure $ docView {query, params, layout}
type Props =
( query :: R.State Query
, params :: R.State T.Params
, layout :: Record LayoutProps )
docView :: Record Props -> R.Element docView :: Record Props -> R.Element
docView p = R.createElement docViewCpt p [] docView props = R.createElement docViewCpt props []
docViewCpt :: R.Component Props docViewCpt :: R.Component Props
docViewCpt = R.hooksComponent "DocView" cpt docViewCpt = R.hooksComponent "G.C.DocsTable.docView" cpt where
where cpt { query, params
cpt p _children = do , layout: { session, nodeId, tabType, listId, corpusId
query <- R.useState' ("" :: Query) , totalRecords, chart, showSearch } } _ = do
tableParams <- R.useState' T.initialParams pure $ H.div {className: "container1"}
pure $ layoutDocview query tableParams p [ H.div {className: "row"}
[ chart
-- | Main layout of the Documents Tab of a Corpus , if showSearch then searchBar query else H.div {} []
layoutDocview :: R.State Query -> R.State T.Params -> Record Props -> R.Element , H.div {className: "col-md-12"}
layoutDocview query tableParams@(params /\ _) p = R.createElement el p [] [ pageLayout {session, nodeId, totalRecords, tabType, listId, corpusId, query: fst query, params} ] ] ]
where
el = R.hooksComponent "LayoutDocView" cpt
cpt {session, nodeId, tabType, listId, corpusId, totalRecords, chart, showSearch} _children = do
pure $ H.div {className: "container1"}
[ H.div {className: "row"}
[ chart
, if showSearch then searchBar query else H.div {} []
, H.div {className: "col-md-12"}
[ pageLoader tableParams {session, nodeId, totalRecords, tabType, listId, corpusId, query: fst query} ] ] ]
-- onClickTrashAll nodeId _ = do -- onClickTrashAll nodeId _ = do
-- launchAff $ deleteAllDocuments p.session nodeId -- launchAff $ deleteAllDocuments p.session nodeId
{-, H.div {className: "col-md-1 col-md-offset-11"} {-, H.div {className: "col-md-1 col-md-offset-11"}
[ pageLoader p.session tableParams {nodeId, totalRecords, tabType, listId, corpusId, query: fst query} ] [ pageLayout p.session params {nodeId, totalRecords, tabType, listId, corpusId, query: fst query} ]
, H.div {className: "col-md-1 col-md-offset-11"} , H.div {className: "col-md-1 col-md-offset-11"}
[ H.button { className: "btn" [ H.button { className: "btn"
, style: {backgroundColor: "peru", color : "white", border : "white"} , style: {backgroundColor: "peru", color : "white", border : "white"}
...@@ -247,7 +255,7 @@ loadPage session {nodeId, tabType, query, listId, corpusId, params: {limit, offs ...@@ -247,7 +255,7 @@ loadPage session {nodeId, tabType, query, listId, corpusId, params: {limit, offs
convOrderBy _ = DateAsc -- TODO convOrderBy _ = DateAsc -- TODO
renderPage :: R.State T.Params -> Record PageLoaderProps -> Array DocumentsView -> R.Element renderPage :: R.State T.Params -> Record PageLayoutProps -> Array DocumentsView -> R.Element
renderPage (_ /\ setTableParams) p@{session} res = R.createElement el p [] renderPage (_ /\ setTableParams) p@{session} res = R.createElement el p []
where where
sid = sessionId session sid = sessionId session
...@@ -295,13 +303,14 @@ renderPage (_ /\ setTableParams) p@{session} res = R.createElement el p [] ...@@ -295,13 +303,14 @@ renderPage (_ /\ setTableParams) p@{session} res = R.createElement el p []
setLocalCategories $ insert nid newCat setLocalCategories $ insert nid newCat
void $ launchAff $ putCategories session nodeId $ CategoryQuery {nodeIds: [nid], category: newCat} void $ launchAff $ putCategories session nodeId $ CategoryQuery {nodeIds: [nid], category: newCat}
pageLoader :: R.State T.Params -> Record PageLoaderProps -> R.Element pageLayout :: Record PageLayoutProps -> R.Element
pageLoader tableParams@(pageParams /\ _) p = R.createElement el p [] pageLayout props = R.createElement pageLayoutCpt props []
where
el = R.hooksComponent "PageLoader" cpt pageLayoutCpt :: R.Component PageLayoutProps
cpt props@{session, nodeId, listId, corpusId, tabType, query} _children = do pageLayoutCpt = R.hooksComponent "G.C.DocsTable.pageLayout" cpt where
useLoader {nodeId, listId, corpusId, tabType, query, params: pageParams} (loadPage session) $ cpt props@{session, nodeId, listId, corpusId, tabType, query, params} _ = do
\loaded -> renderPage tableParams props loaded useLoader {nodeId, listId, corpusId, tabType, query, params: fst params} (loadPage session) $
\loaded -> renderPage params props loaded
--------------------------------------------------------- ---------------------------------------------------------
sampleData' :: DocumentsView sampleData' :: DocumentsView
......
...@@ -65,7 +65,7 @@ tabsCpt = R.hooksComponent "G.P.Annuaire.User.Contacts.Tabs.tabs" cpt ...@@ -65,7 +65,7 @@ tabsCpt = R.hooksComponent "G.P.Annuaire.User.Contacts.Tabs.tabs" cpt
commView = {session, defaultListId, nodeId, mode: Communication} commView = {session, defaultListId, nodeId, mode: Communication}
chart = mempty chart = mempty
totalRecords = 4736 -- TODO totalRecords = 4736 -- TODO
docs = DT.docView docs = DT.docViewLayout
{ session, nodeId, chart, totalRecords { session, nodeId, chart, totalRecords
, tabType: TabPairing TabDocs , tabType: TabPairing TabDocs
, listId: defaultListId , listId: defaultListId
......
...@@ -62,9 +62,9 @@ docViewCpt :: forall a. R.Component (DocViewProps a) ...@@ -62,9 +62,9 @@ docViewCpt :: forall a. R.Component (DocViewProps a)
docViewCpt = R.hooksComponent "DocViewWithCorpus" cpt docViewCpt = R.hooksComponent "DocViewWithCorpus" cpt
where where
cpt {session, corpusId, corpusData: {defaultListId}, tabType} _children = do cpt {session, corpusId, corpusData: {defaultListId}, tabType} _children = do
pure $ DT.docView $ params tabType pure $ DT.docViewLayout $ params tabType
where where
params :: forall b. TabSubType b -> Record DT.Props params :: forall b. TabSubType b -> Record DT.LayoutProps
params TabDocs = params TabDocs =
{ nodeId: corpusId { nodeId: corpusId
-- ^ TODO merge nodeId and corpusId in DT -- ^ TODO merge nodeId and corpusId in DT
......
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