Tabs refactoring

parent 9c6927cb
...@@ -11,17 +11,20 @@ import Data.Tuple (Tuple(..)) ...@@ -11,17 +11,20 @@ import Data.Tuple (Tuple(..))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import React.DOM (div, h3, hr, i, p, text) import React.DOM (div, h3, hr, i, p, text)
import React.DOM.Props (className, style) import React.DOM.Props (className, style)
import Thermite ( Render, Spec, PerformAction, focus import Thermite ( Render, Spec, PerformAction, focus, cmapProps
, simpleSpec, modifyState, noState) , simpleSpec, modifyState, noState)
-------------------------------------------------------- --------------------------------------------------------
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Components.Node (NodePoly(..)) import Gargantext.Components.Node (NodePoly(..))
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 as Tabs
import Gargantext.Pages.Corpus.Tabs.States as Tabs import Gargantext.Pages.Corpus.Tabs.States as Tabs
import Gargantext.Pages.Corpus.Tabs.Actions as Tabs import Gargantext.Pages.Corpus.Tabs.Actions as Tabs
import Gargantext.Pages.Corpus.Tabs.Specs as Tabs import Gargantext.Pages.Corpus.Tabs.Specs as Tabs
------------------------------------------------------------------- -------------------------------------------------------------------
type Props = Tabs.Props
type HeaderState = { info :: Maybe (NodePoly CorpusInfo) } type HeaderState = { info :: Maybe (NodePoly CorpusInfo) }
type State = { headerView :: HeaderState type State = { headerView :: HeaderState
, tabsView :: Tabs.State , tabsView :: Tabs.State
...@@ -102,8 +105,8 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where ...@@ -102,8 +105,8 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where
pure $ CorpusInfo {title, desc, query, authors, chart} pure $ CorpusInfo {title, desc, query, authors, chart}
------------------------------------------------------------------------ ------------------------------------------------------------------------
layout :: Spec State {} Action layout :: Spec State Props Action
layout = focus _headerView _headerAction corpusHeaderSpec layout = cmapProps (const {}) (focus _headerView _headerAction corpusHeaderSpec)
<> focus _tabsView _tabsAction Tabs.statefulTabs <> focus _tabsView _tabsAction Tabs.statefulTabs
corpusHeaderSpec :: Spec HeaderState {} HeaderAction corpusHeaderSpec :: Spec HeaderState {} HeaderAction
......
module Gargantext.Pages.Corpus.Tabs.Authors where module Gargantext.Pages.Corpus.Tabs.Authors where
import Data.Array (fold)
import Gargantext.Pages.Corpus.Tabs.Documents as D
import Prelude hiding (div) import Prelude hiding (div)
import React.DOM (h3, text) import React.DOM (h3, text)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, simpleSpec) import Thermite (PerformAction, Render, Spec, defaultPerformAction, simpleSpec)
type State = D.State type State = {}
initialState :: State initialState :: State
initialState = D.initialState initialState = {}
type Action = D.Action type Action = Void
authorSpec :: Spec State {} Action authorSpec :: Spec State {} Action
authorSpec = simpleSpec defaultPerformAction render authorSpec = simpleSpec defaultPerformAction render
...@@ -20,6 +18,3 @@ authorSpec = simpleSpec defaultPerformAction render ...@@ -20,6 +18,3 @@ authorSpec = simpleSpec defaultPerformAction render
render :: Render State {} Action render :: Render State {} Action
render dispatch _ state _ = render dispatch _ state _ =
[ h3 [] [text "AuthorView"]] [ h3 [] [text "AuthorView"]]
authorspec' :: Spec State {} Action
authorspec' = fold [authorSpec, D.layoutDocview]
...@@ -31,17 +31,18 @@ import Gargantext.Pages.Corpus.Dashboard (globalPublis) ...@@ -31,17 +31,18 @@ import Gargantext.Pages.Corpus.Dashboard (globalPublis)
-- TODO: Filter is Pending -- TODO: Filter is Pending
-- TODO: When a pagination link is clicked, reload data. -- TODO: When a pagination link is clicked, reload data.
data Action type Props =
= UpdateNodeId Int
type State =
{ totalRecords :: Int { totalRecords :: Int
, nodeId :: Maybe Int -- /!\ When changing the pages of the Table, NodeId , nodeId :: Int -- /!\ When changing the pages of the Table, NodeId
-- is needed to reload Data (other solution is using -- is needed to reload Data (other solution is using
-- NodeId as a parameter -- NodeId as a parameter
-- NP,TODO this should not be in state -- NP,TODO this should not be in state
} }
type State = {}
type Action = Void
newtype DocumentsView newtype DocumentsView
= DocumentsView = DocumentsView
{ _id :: Int { _id :: Int
...@@ -120,16 +121,11 @@ filterSpec = simpleSpec defaultPerformAction render ...@@ -120,16 +121,11 @@ filterSpec = simpleSpec defaultPerformAction render
]] ]]
-- | Main layout of the Documents Tab of a Corpus -- | Main layout of the Documents Tab of a Corpus
layoutDocview :: Spec State {} Action layoutDocview :: Spec State Props Action
layoutDocview = simpleSpec performAction render layoutDocview = simpleSpec absurd render
where where
performAction :: PerformAction State {} Action render :: Render State Props Action
performAction (UpdateNodeId nId) _ _ = do render dispatch {nodeId, totalRecords} _ _ =
void $ modifyState $ _ { nodeId = Just nId }
logs $ "writing NodeId" <> show nId
render :: Render State {} Action
render dispatch _ {nodeId, totalRecords} _ =
[ div [className "container1"] [ div [className "container1"]
[ div [className "row"] [ div [className "row"]
[ chart globalPublis [ chart globalPublis
...@@ -181,10 +177,10 @@ layoutDocview = simpleSpec performAction render ...@@ -181,10 +177,10 @@ layoutDocview = simpleSpec performAction render
mock :: Boolean mock :: Boolean
mock = false mock = false
loadPage :: {nodeId :: Maybe Int, limit :: Int, offset :: Int} -> Aff (Either String (Array DocumentsView)) loadPage :: {nodeId :: Int, limit :: Int, offset :: Int} -> Aff (Either String (Array DocumentsView))
loadPage {nodeId, limit, offset} = do loadPage {nodeId, limit, offset} = do
logs "loading documents page: loadPage with Offset and limit" logs "loading documents page: loadPage with Offset and limit"
res <- get $ toUrl Back (Children offset limit) $ maybe 0 identity nodeId res <- get $ toUrl Back (Children offset limit) nodeId
case res of case res of
Left err -> do Left err -> do
_ <- logs "Err: loading page documents" _ <- logs "Err: loading page documents"
...@@ -222,8 +218,7 @@ sampleDocuments :: Array (Tuple String String) ...@@ -222,8 +218,7 @@ sampleDocuments :: Array (Tuple String String)
sampleDocuments = [Tuple "Macroscopic dynamics of the fusion process" "Journal de Physique Lettres",Tuple "Effects of static and cyclic fatigue at high temperature upon reaction bonded silicon nitride" "Journal de Physique Colloques",Tuple "Reliability of metal/glass-ceramic junctions made by solid state bonding" "Journal de Physique Colloques",Tuple "High temperature mechanical properties and intergranular structure of sialons" "Journal de Physique Colloques",Tuple "SOLUTIONS OF THE LANDAU-VLASOV EQUATION IN NUCLEAR PHYSICS" "Journal de Physique Colloques",Tuple "A STUDY ON THE FUSION REACTION 139La + 12C AT 50 MeV/u WITH THE VUU EQUATION" "Journal de Physique Colloques",Tuple "Atomic structure of \"vitreous\" interfacial films in sialon" "Journal de Physique Colloques",Tuple "MICROSTRUCTURAL AND ANALYTICAL CHARACTERIZATION OF Al2O3/Al-Mg COMPOSITE INTERFACES" "Journal de Physique Colloques",Tuple "Development of oxidation resistant high temperature NbTiAl alloys and intermetallics" "Journal de Physique IV Colloque",Tuple "Determination of brazed joint constitutive law by inverse method" "Journal de Physique IV Colloque",Tuple "Two dimensional estimates from ocean SAR images" "Nonlinear Processes in Geophysics",Tuple "Comparison Between New Carbon Nanostructures Produced by Plasma with Industrial Carbon Black Grades" "Journal de Physique III",Tuple "<i>Letter to the Editor:</i> SCIPION, a new flexible ionospheric sounder in Senegal" "Annales Geophysicae",Tuple "Is reducibility in nuclear multifragmentation related to thermal scaling?" "Physics Letters B",Tuple "Independence of fragment charge distributions of the size of heavy multifragmenting sources" "Physics Letters B",Tuple "Hard photons and neutral pions as probes of hot and dense nuclear matter" "Nuclear Physics A",Tuple "Surveying the nuclear caloric curve" "Physics Letters B",Tuple "A hot expanding source in 50 A MeV Xe+Sn central reactions" "Physics Letters B"] sampleDocuments = [Tuple "Macroscopic dynamics of the fusion process" "Journal de Physique Lettres",Tuple "Effects of static and cyclic fatigue at high temperature upon reaction bonded silicon nitride" "Journal de Physique Colloques",Tuple "Reliability of metal/glass-ceramic junctions made by solid state bonding" "Journal de Physique Colloques",Tuple "High temperature mechanical properties and intergranular structure of sialons" "Journal de Physique Colloques",Tuple "SOLUTIONS OF THE LANDAU-VLASOV EQUATION IN NUCLEAR PHYSICS" "Journal de Physique Colloques",Tuple "A STUDY ON THE FUSION REACTION 139La + 12C AT 50 MeV/u WITH THE VUU EQUATION" "Journal de Physique Colloques",Tuple "Atomic structure of \"vitreous\" interfacial films in sialon" "Journal de Physique Colloques",Tuple "MICROSTRUCTURAL AND ANALYTICAL CHARACTERIZATION OF Al2O3/Al-Mg COMPOSITE INTERFACES" "Journal de Physique Colloques",Tuple "Development of oxidation resistant high temperature NbTiAl alloys and intermetallics" "Journal de Physique IV Colloque",Tuple "Determination of brazed joint constitutive law by inverse method" "Journal de Physique IV Colloque",Tuple "Two dimensional estimates from ocean SAR images" "Nonlinear Processes in Geophysics",Tuple "Comparison Between New Carbon Nanostructures Produced by Plasma with Industrial Carbon Black Grades" "Journal de Physique III",Tuple "<i>Letter to the Editor:</i> SCIPION, a new flexible ionospheric sounder in Senegal" "Annales Geophysicae",Tuple "Is reducibility in nuclear multifragmentation related to thermal scaling?" "Physics Letters B",Tuple "Independence of fragment charge distributions of the size of heavy multifragmenting sources" "Physics Letters B",Tuple "Hard photons and neutral pions as probes of hot and dense nuclear matter" "Nuclear Physics A",Tuple "Surveying the nuclear caloric curve" "Physics Letters B",Tuple "A hot expanding source in 50 A MeV Xe+Sn central reactions" "Physics Letters B"]
initialState :: State initialState :: State
initialState = { totalRecords: if mock then length sampleData else 47361 -- TODO initialState = {}
, nodeId: Nothing }
newtype SearchQuery = SearchQuery newtype SearchQuery = SearchQuery
{ {
......
module Gargantext.Pages.Corpus.Tabs.Sources where module Gargantext.Pages.Corpus.Tabs.Sources where
import Data.Array (fold)
import Gargantext.Pages.Corpus.Tabs.Documents as D
import Prelude hiding (div) import Prelude hiding (div)
import React.DOM (h3, text) import React.DOM (h3, text)
import Thermite (Render, Spec, defaultPerformAction, simpleSpec) import Thermite (Render, Spec, defaultPerformAction, simpleSpec)
-- NP: TODO the state should be only the one required by sourceSpec not sourcespec' type State = {}
type State = D.State
initialState :: State
initialState = {}
initialState :: D.State type Action = Void
initialState = D.initialState
type Action = D.Action
sourceSpec :: Spec State {} Action sourceSpec :: Spec State {} Action
sourceSpec = simpleSpec defaultPerformAction render sourceSpec = simpleSpec defaultPerformAction render
...@@ -23,6 +18,3 @@ sourceSpec = simpleSpec defaultPerformAction render ...@@ -23,6 +18,3 @@ sourceSpec = simpleSpec defaultPerformAction render
render :: Render State {} Action render :: Render State {} Action
render dispatch _ state _ = render dispatch _ state _ =
[ h3 [] [text "Source view"]] [ h3 [] [text "Source view"]]
sourcespec' :: Spec State {} Action
sourcespec' = sourceSpec <> D.layoutDocview
...@@ -5,6 +5,7 @@ import Prelude hiding (div) ...@@ -5,6 +5,7 @@ import Prelude hiding (div)
import Data.List (fromFoldable) import Data.List (fromFoldable)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Gargantext.Pages.Corpus.Tabs.Types (Props)
import Gargantext.Pages.Corpus.Tabs.States (State(), _doclens, _sourcelens, _authorlens, _termslens, _tablens, initialState) import Gargantext.Pages.Corpus.Tabs.States (State(), _doclens, _sourcelens, _authorlens, _termslens, _tablens, initialState)
import Gargantext.Pages.Corpus.Tabs.Actions (Action(), _docAction, _sourceAction, _authorAction, _termsAction, _tabAction) import Gargantext.Pages.Corpus.Tabs.Actions (Action(), _docAction, _sourceAction, _authorAction, _termsAction, _tabAction)
...@@ -13,13 +14,13 @@ import Gargantext.Pages.Corpus.Tabs.Sources as SV ...@@ -13,13 +14,13 @@ import Gargantext.Pages.Corpus.Tabs.Sources as SV
import Gargantext.Pages.Corpus.Tabs.Authors as AV import Gargantext.Pages.Corpus.Tabs.Authors as AV
import Gargantext.Pages.Corpus.Tabs.Terms as TV import Gargantext.Pages.Corpus.Tabs.Terms as TV
import Gargantext.Components.Tab as Tab import Gargantext.Components.Tab as Tab
import Thermite (Spec, focus, hideState) import Thermite (Spec, focus, hideState, cmapProps)
pureTabs :: Spec {} {} Void pureTabs :: Spec {} Props Void
pureTabs = hideState initialState statefulTabs pureTabs = hideState initialState statefulTabs
statefulTabs :: Spec State {} Action statefulTabs :: Spec State Props Action
statefulTabs = statefulTabs =
Tab.tabs _tablens _tabAction $ fromFoldable [ Tuple "Documents" docPageSpec Tab.tabs _tablens _tabAction $ fromFoldable [ Tuple "Documents" docPageSpec
, Tuple "Authors" authorPageSpec , Tuple "Authors" authorPageSpec
...@@ -27,14 +28,17 @@ statefulTabs = ...@@ -27,14 +28,17 @@ statefulTabs =
, Tuple "Terms" termsPageSpec , Tuple "Terms" termsPageSpec
] ]
docPageSpec :: Spec State {} Action docPageSpec :: Spec State Props Action
docPageSpec = focus _doclens _docAction DV.layoutDocview docPageSpec = focus _doclens _docAction DV.layoutDocview
authorPageSpec :: Spec State {} Action authorPageSpec :: Spec State Props Action
authorPageSpec = focus _authorlens _authorAction AV.authorspec' authorPageSpec = cmapProps (const {}) (focus _authorlens _authorAction AV.authorSpec)
<> docPageSpec
sourcePageSpec :: Spec State {} Action sourcePageSpec :: Spec State Props Action
sourcePageSpec = focus _sourcelens _sourceAction SV.sourcespec' sourcePageSpec = cmapProps (const {}) (focus _sourcelens _sourceAction SV.sourceSpec)
<> docPageSpec
termsPageSpec :: Spec State {} Action termsPageSpec :: Spec State Props Action
termsPageSpec = focus _termslens _termsAction TV.termSpec' termsPageSpec = cmapProps (const {}) (focus _termslens _termsAction TV.termsSpec)
<> docPageSpec
module Gargantext.Pages.Corpus.Tabs.Terms where module Gargantext.Pages.Corpus.Tabs.Terms where
import Data.Array (fold) import Data.Array (fold)
import Gargantext.Pages.Corpus.Tabs.Documents as D
import Prelude hiding (div) import Prelude hiding (div)
import React.DOM (h3, text) import React.DOM (h3, text)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, simpleSpec) import Thermite (PerformAction, Render, Spec, defaultPerformAction, simpleSpec)
type State = {}
type State = D.State initialState :: State
initialState = {}
initialState :: D.State
initialState = D.initialState
type Action = D.Action
type Action = Void
termsSpec :: Spec State {} Action termsSpec :: Spec State {} Action
termsSpec = simpleSpec defaultPerformAction render termsSpec = simpleSpec defaultPerformAction render
...@@ -23,6 +19,3 @@ termsSpec = simpleSpec defaultPerformAction render ...@@ -23,6 +19,3 @@ termsSpec = simpleSpec defaultPerformAction render
render :: Render State {} Action render :: Render State {} Action
render dispatch _ state _ = render dispatch _ state _ =
[ h3 [] [text "Terms view"]] [ h3 [] [text "Terms view"]]
termSpec' :: Spec State {} Action
termSpec' = fold [termsSpec, D.layoutDocview]
...@@ -39,7 +39,6 @@ dispatchAction dispatcher _ AddCorpus = do ...@@ -39,7 +39,6 @@ dispatchAction dispatcher _ AddCorpus = do
dispatchAction dispatcher _ (Corpus n) = do dispatchAction dispatcher _ (Corpus n) = do
dispatcher $ SetRoute $ Corpus n dispatcher $ SetRoute $ Corpus n
dispatcher $ CorpusAction $ Corpus.TabsA $ TabsA.DocviewA $ D.UpdateNodeId n
dispatcher $ CorpusAction $ Corpus.HeaderA $ Corpus.Load n dispatcher $ CorpusAction $ Corpus.HeaderA $ Corpus.Load n
dispatchAction dispatcher _ SearchView = do dispatchAction dispatcher _ SearchView = do
......
...@@ -7,7 +7,7 @@ import Effect (Effect) ...@@ -7,7 +7,7 @@ import Effect (Effect)
import React (ReactElement) import React (ReactElement)
import React.DOM (a, button, div, footer, hr', img, input, li, p, span, text, ul) import React.DOM (a, button, div, footer, hr', img, input, li, p, span, text, ul)
import React.DOM.Props (_data, _id, _type, aria, className, href, onChange, onClick, placeholder, role, src, style, tabIndex, target, title) import React.DOM.Props (_data, _id, _type, aria, className, href, onChange, onClick, placeholder, role, src, style, tabIndex, target, title)
import Thermite (Render, Spec, _render, defaultPerformAction, defaultRender, focus, simpleSpec, withState, noState) import Thermite (Render, Spec, _render, defaultPerformAction, defaultRender, focus, simpleSpec, withState, noState, cmapProps)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Prelude import Gargantext.Prelude
...@@ -19,9 +19,7 @@ import Gargantext.Pages.Annuaire as A ...@@ -19,9 +19,7 @@ import Gargantext.Pages.Annuaire as A
import Gargantext.Pages.Annuaire.User.Users as U import Gargantext.Pages.Annuaire.User.Users as U
import Gargantext.Pages.Corpus as Corpus import Gargantext.Pages.Corpus as Corpus
import Gargantext.Pages.Corpus.Document as Annotation import Gargantext.Pages.Corpus.Document as Annotation
import Gargantext.Pages.Corpus.Tabs as TV
import Gargantext.Pages.Corpus.Dashboard as Dsh import Gargantext.Pages.Corpus.Dashboard as Dsh
import Gargantext.Pages.Corpus.Tabs.Documents as DV
import Gargantext.Pages.Corpus.Graph as GE import Gargantext.Pages.Corpus.Graph as GE
import Gargantext.Pages.Corpus.Tabs.Terms.NgramsTable as NG import Gargantext.Pages.Corpus.Tabs.Terms.NgramsTable as NG
import Gargantext.Pages.Home as L import Gargantext.Pages.Home as L
...@@ -57,7 +55,9 @@ pagesComponent s = case s.currentRoute of ...@@ -57,7 +55,9 @@ pagesComponent s = case s.currentRoute of
selectSpec Login = focus _loginState _loginAction LN.renderSpec selectSpec Login = focus _loginState _loginAction LN.renderSpec
selectSpec (Folder i) = layout0 $ noState F.layoutFolder selectSpec (Folder i) = layout0 $ noState F.layoutFolder
selectSpec (Corpus i) = layout0 $ focus _corpusState _corpusAction Corpus.layout selectSpec (Corpus i) = layout0 $
cmapProps (const {nodeId: i, totalRecords: 47361}) -- TODO
(focus _corpusState _corpusAction Corpus.layout)
selectSpec AddCorpus = layout0 $ focus _addCorpusState _addCorpusAction AC.layoutAddcorpus selectSpec AddCorpus = layout0 $ focus _addCorpusState _addCorpusAction AC.layoutAddcorpus
selectSpec SearchView = layout0 $ focus _searchState _searchAction S.searchSpec selectSpec SearchView = layout0 $ focus _searchState _searchAction S.searchSpec
selectSpec (Document i) = layout0 $ focus _documentViewState _documentViewAction Annotation.docview selectSpec (Document i) = layout0 $ focus _documentViewState _documentViewAction Annotation.docview
......
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