Tabs refactoring

parent 9c6927cb
......@@ -11,17 +11,20 @@ import Data.Tuple (Tuple(..))
import Effect.Aff (Aff)
import React.DOM (div, h3, hr, i, p, text)
import React.DOM.Props (className, style)
import Thermite ( Render, Spec, PerformAction, focus
import Thermite ( Render, Spec, PerformAction, focus, cmapProps
, simpleSpec, modifyState, noState)
--------------------------------------------------------
import Gargantext.Prelude
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Config (toUrl, NodeType(..), End(..))
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.Actions as Tabs
import Gargantext.Pages.Corpus.Tabs.Specs as Tabs
-------------------------------------------------------------------
type Props = Tabs.Props
type HeaderState = { info :: Maybe (NodePoly CorpusInfo) }
type State = { headerView :: HeaderState
, tabsView :: Tabs.State
......@@ -102,8 +105,8 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where
pure $ CorpusInfo {title, desc, query, authors, chart}
------------------------------------------------------------------------
layout :: Spec State {} Action
layout = focus _headerView _headerAction corpusHeaderSpec
layout :: Spec State Props Action
layout = cmapProps (const {}) (focus _headerView _headerAction corpusHeaderSpec)
<> focus _tabsView _tabsAction Tabs.statefulTabs
corpusHeaderSpec :: Spec HeaderState {} HeaderAction
......
module Gargantext.Pages.Corpus.Tabs.Authors where
import Data.Array (fold)
import Gargantext.Pages.Corpus.Tabs.Documents as D
import Prelude hiding (div)
import React.DOM (h3, text)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, simpleSpec)
type State = D.State
type State = {}
initialState :: State
initialState = D.initialState
initialState = {}
type Action = D.Action
type Action = Void
authorSpec :: Spec State {} Action
authorSpec = simpleSpec defaultPerformAction render
......@@ -20,6 +18,3 @@ authorSpec = simpleSpec defaultPerformAction render
render :: Render State {} Action
render dispatch _ state _ =
[ h3 [] [text "AuthorView"]]
authorspec' :: Spec State {} Action
authorspec' = fold [authorSpec, D.layoutDocview]
......@@ -31,17 +31,18 @@ import Gargantext.Pages.Corpus.Dashboard (globalPublis)
-- TODO: Filter is Pending
-- TODO: When a pagination link is clicked, reload data.
data Action
= UpdateNodeId Int
type State =
type Props =
{ totalRecords :: Int
, nodeId :: Maybe Int -- /!\ When changing the pages of the Table, NodeId
-- is needed to reload Data (other solution is using
-- NodeId as a parameter
-- NP,TODO this should not be in state
, nodeId :: Int -- /!\ When changing the pages of the Table, NodeId
-- is needed to reload Data (other solution is using
-- NodeId as a parameter
-- NP,TODO this should not be in state
}
type State = {}
type Action = Void
newtype DocumentsView
= DocumentsView
{ _id :: Int
......@@ -120,16 +121,11 @@ filterSpec = simpleSpec defaultPerformAction render
]]
-- | Main layout of the Documents Tab of a Corpus
layoutDocview :: Spec State {} Action
layoutDocview = simpleSpec performAction render
layoutDocview :: Spec State Props Action
layoutDocview = simpleSpec absurd render
where
performAction :: PerformAction State {} Action
performAction (UpdateNodeId nId) _ _ = do
void $ modifyState $ _ { nodeId = Just nId }
logs $ "writing NodeId" <> show nId
render :: Render State {} Action
render dispatch _ {nodeId, totalRecords} _ =
render :: Render State Props Action
render dispatch {nodeId, totalRecords} _ _ =
[ div [className "container1"]
[ div [className "row"]
[ chart globalPublis
......@@ -181,10 +177,10 @@ layoutDocview = simpleSpec performAction render
mock :: Boolean
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
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
Left err -> do
_ <- logs "Err: loading page documents"
......@@ -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"]
initialState :: State
initialState = { totalRecords: if mock then length sampleData else 47361 -- TODO
, nodeId: Nothing }
initialState = {}
newtype SearchQuery = SearchQuery
{
......
module Gargantext.Pages.Corpus.Tabs.Sources where
import Data.Array (fold)
import Gargantext.Pages.Corpus.Tabs.Documents as D
import Prelude hiding (div)
import React.DOM (h3, text)
import Thermite (Render, Spec, defaultPerformAction, simpleSpec)
-- NP: TODO the state should be only the one required by sourceSpec not sourcespec'
type State = D.State
type State = {}
initialState :: State
initialState = {}
initialState :: D.State
initialState = D.initialState
type Action = D.Action
type Action = Void
sourceSpec :: Spec State {} Action
sourceSpec = simpleSpec defaultPerformAction render
......@@ -23,6 +18,3 @@ sourceSpec = simpleSpec defaultPerformAction render
render :: Render State {} Action
render dispatch _ state _ =
[ h3 [] [text "Source view"]]
sourcespec' :: Spec State {} Action
sourcespec' = sourceSpec <> D.layoutDocview
......@@ -5,6 +5,7 @@ import Prelude hiding (div)
import Data.List (fromFoldable)
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.Actions (Action(), _docAction, _sourceAction, _authorAction, _termsAction, _tabAction)
......@@ -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.Terms as TV
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
statefulTabs :: Spec State {} Action
statefulTabs :: Spec State Props Action
statefulTabs =
Tab.tabs _tablens _tabAction $ fromFoldable [ Tuple "Documents" docPageSpec
, Tuple "Authors" authorPageSpec
......@@ -27,14 +28,17 @@ statefulTabs =
, Tuple "Terms" termsPageSpec
]
docPageSpec :: Spec State {} Action
docPageSpec :: Spec State Props Action
docPageSpec = focus _doclens _docAction DV.layoutDocview
authorPageSpec :: Spec State {} Action
authorPageSpec = focus _authorlens _authorAction AV.authorspec'
authorPageSpec :: Spec State Props Action
authorPageSpec = cmapProps (const {}) (focus _authorlens _authorAction AV.authorSpec)
<> docPageSpec
sourcePageSpec :: Spec State {} Action
sourcePageSpec = focus _sourcelens _sourceAction SV.sourcespec'
sourcePageSpec :: Spec State Props Action
sourcePageSpec = cmapProps (const {}) (focus _sourcelens _sourceAction SV.sourceSpec)
<> docPageSpec
termsPageSpec :: Spec State {} Action
termsPageSpec = focus _termslens _termsAction TV.termSpec'
termsPageSpec :: Spec State Props Action
termsPageSpec = cmapProps (const {}) (focus _termslens _termsAction TV.termsSpec)
<> docPageSpec
module Gargantext.Pages.Corpus.Tabs.Terms where
import Data.Array (fold)
import Gargantext.Pages.Corpus.Tabs.Documents as D
import Prelude hiding (div)
import React.DOM (h3, text)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, simpleSpec)
type State = {}
type State = D.State
initialState :: D.State
initialState = D.initialState
type Action = D.Action
initialState :: State
initialState = {}
type Action = Void
termsSpec :: Spec State {} Action
termsSpec = simpleSpec defaultPerformAction render
......@@ -23,6 +19,3 @@ termsSpec = simpleSpec defaultPerformAction render
render :: Render State {} Action
render dispatch _ state _ =
[ h3 [] [text "Terms view"]]
termSpec' :: Spec State {} Action
termSpec' = fold [termsSpec, D.layoutDocview]
......@@ -39,7 +39,6 @@ dispatchAction dispatcher _ AddCorpus = do
dispatchAction dispatcher _ (Corpus n) = do
dispatcher $ SetRoute $ Corpus n
dispatcher $ CorpusAction $ Corpus.TabsA $ TabsA.DocviewA $ D.UpdateNodeId n
dispatcher $ CorpusAction $ Corpus.HeaderA $ Corpus.Load n
dispatchAction dispatcher _ SearchView = do
......
......@@ -7,7 +7,7 @@ import Effect (Effect)
import React (ReactElement)
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 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 Gargantext.Prelude
......@@ -19,9 +19,7 @@ import Gargantext.Pages.Annuaire as A
import Gargantext.Pages.Annuaire.User.Users as U
import Gargantext.Pages.Corpus as Corpus
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.Tabs.Documents as DV
import Gargantext.Pages.Corpus.Graph as GE
import Gargantext.Pages.Corpus.Tabs.Terms.NgramsTable as NG
import Gargantext.Pages.Home as L
......@@ -57,7 +55,9 @@ pagesComponent s = case s.currentRoute of
selectSpec Login = focus _loginState _loginAction LN.renderSpec
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 SearchView = layout0 $ focus _searchState _searchAction S.searchSpec
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