[REFACTOR] re-org tabs state and actions

parent b1bb73de
...@@ -12,36 +12,24 @@ import Effect.Aff (Aff) ...@@ -12,36 +12,24 @@ 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
, simpleSpec, modifyState) , 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.States as Tabs
-- Tabs import Gargantext.Pages.Corpus.Tabs.Actions as Tabs
import Gargantext.Pages.Corpus.Tabs.Documents as D import Gargantext.Pages.Corpus.Tabs.Specs as Tabs
import Gargantext.Pages.Corpus.Tabs.Sources as S
import Gargantext.Pages.Corpus.Tabs.Authors as A
import Gargantext.Pages.Corpus.Tabs.Terms as T
import Gargantext.Components.Tab as Tab
------------------------------------------------------------------- -------------------------------------------------------------------
type HeaderState = { info :: Maybe (NodePoly CorpusInfo) } type HeaderState = { info :: Maybe (NodePoly CorpusInfo) }
type State = { headerView :: HeaderState type State = { headerView :: HeaderState
, docsView :: D.State , tabsView :: Tabs.State
, authorsView :: A.State
, sourcesView :: S.State
, termsView :: T.State
, activeTab :: Int
} }
initialState :: State initialState :: State
initialState = { headerView : { info : Nothing } initialState = { headerView : { info : Nothing }
, docsView : D.initialState , tabsView : Tabs.initialState
, authorsView : A.initialState
, sourcesView : S.initialState
, termsView : T.initialState
, activeTab : 0
} }
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -51,29 +39,14 @@ _info = lens (\s -> s.info) (\s ss -> s{info = ss}) ...@@ -51,29 +39,14 @@ _info = lens (\s -> s.info) (\s ss -> s{info = ss})
_headerView :: forall a b. Lens' { headerView :: a | b } a _headerView :: forall a b. Lens' { headerView :: a | b } a
_headerView = lens (\s -> s.headerView) (\s ss -> s{headerView = ss}) _headerView = lens (\s -> s.headerView) (\s ss -> s{headerView = ss})
_doclens :: Lens' State D.State _tabsView :: forall a b. Lens' { tabsView :: a | b } a
_doclens = lens (\s -> s.docsView) (\s ss -> s {docsView = ss}) _tabsView = lens (\s -> s.tabsView) (\s ss -> s{tabsView = ss})
_authorlens :: Lens' State A.State
_authorlens = lens (\s -> s.authorsView) (\s ss -> s {authorsView = ss})
_sourcelens :: Lens' State S.State
_sourcelens = lens (\s -> s.sourcesView) (\s ss -> s {sourcesView = ss})
_termslens :: Lens' State T.State
_termslens = lens (\s -> s.termsView) (\s ss -> s {termsView = ss})
_tablens :: Lens' State Tab.State
_tablens = lens (\s -> s.activeTab) (\s ss -> s {activeTab = ss})
------------------------------------------------------------------------ ------------------------------------------------------------------------
data HeaderAction = Load Int data HeaderAction = Load Int
data Action = HeaderA HeaderAction data Action
| DocviewA D.Action = HeaderA HeaderAction
| AuthorviewA A.Action | TabsA Tabs.Action
| SourceviewA S.Action
| TermsviewA T.Action
| TabViewA Tab.Action
_headerAction :: Prism' Action HeaderAction _headerAction :: Prism' Action HeaderAction
_headerAction = prism HeaderA \ action -> _headerAction = prism HeaderA \ action ->
...@@ -81,35 +54,12 @@ _headerAction = prism HeaderA \ action -> ...@@ -81,35 +54,12 @@ _headerAction = prism HeaderA \ action ->
HeaderA haction -> Right haction HeaderA haction -> Right haction
_-> Left action _-> Left action
_docAction :: Prism' Action D.Action _tabsAction :: Prism' Action Tabs.Action
_docAction = prism DocviewA \ action -> _tabsAction = prism TabsA \ action ->
case action of
DocviewA laction -> Right laction
_-> Left action
_authorAction :: Prism' Action A.Action
_authorAction = prism AuthorviewA \ action ->
case action of
AuthorviewA laction -> Right laction
_-> Left action
_sourceAction :: Prism' Action S.Action
_sourceAction = prism SourceviewA \ action ->
case action of case action of
SourceviewA laction -> Right laction TabsA taction -> Right taction
_-> Left action _-> Left action
_termsAction :: Prism' Action T.Action
_termsAction = prism TermsviewA \ action ->
case action of
TermsviewA laction -> Right laction
_-> Left action
_tabAction :: Prism' Action Tab.Action
_tabAction = prism TabViewA \ action ->
case action of
TabViewA laction -> Right laction
_-> Left action
_loadAction :: Prism' HeaderAction Int _loadAction :: Prism' HeaderAction Int
_loadAction = prism Load \ action -> _loadAction = prism Load \ action ->
...@@ -153,7 +103,8 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where ...@@ -153,7 +103,8 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where
------------------------------------------------------------------------ ------------------------------------------------------------------------
layout :: Spec State {} Action layout :: Spec State {} Action
layout = focus _headerView _headerAction corpusHeaderSpec <> facets layout = focus _headerView _headerAction corpusHeaderSpec
<> focus _tabsView _tabsAction Tabs.statefulTabs
corpusHeaderSpec :: Spec HeaderState {} HeaderAction corpusHeaderSpec :: Spec HeaderState {} HeaderAction
corpusHeaderSpec = simpleSpec performAction render corpusHeaderSpec = simpleSpec performAction render
...@@ -203,27 +154,3 @@ performAction (Load nId) _ _ = do ...@@ -203,27 +154,3 @@ performAction (Load nId) _ _ = do
getNode :: Int -> Aff (Either String (NodePoly CorpusInfo)) getNode :: Int -> Aff (Either String (NodePoly CorpusInfo))
getNode id = get $ toUrl Back Node id getNode id = get $ toUrl Back Node id
------------------------------------------------------------------------
-- Tabs
------------------------------------------------------------------------
facets :: Spec State {} Action
facets =
Tab.tabs _tablens _tabAction $ fromFoldable [ Tuple "Documents" docPageSpec
, Tuple "Authors" authorPageSpec
, Tuple "Sources" sourcePageSpec
, Tuple "Terms" termsPageSpec
]
docPageSpec :: Spec State {} Action
docPageSpec = focus _doclens _docAction D.layoutDocview
authorPageSpec :: Spec State {} Action
authorPageSpec = focus _authorlens _authorAction A.authorspec'
sourcePageSpec :: Spec State {} Action
sourcePageSpec = focus _sourcelens _sourceAction S.sourcespec'
termsPageSpec :: Spec State {} Action
termsPageSpec = focus _termslens _termsAction T.termSpec'
...@@ -46,6 +46,3 @@ _tabAction = prism TabViewA \ action -> ...@@ -46,6 +46,3 @@ _tabAction = prism TabViewA \ action ->
case action of case action of
TabViewA laction -> Right laction TabViewA laction -> Right laction
_-> Left action _-> Left action
...@@ -16,15 +16,15 @@ import Gargantext.Components.Tab as Tab ...@@ -16,15 +16,15 @@ import Gargantext.Components.Tab as Tab
import Thermite (Spec, focus, hideState) import Thermite (Spec, focus, hideState)
pureTab1 :: Spec {} {} Void pureTabs :: Spec {} {} Void
pureTab1 = hideState initialState statefulTab1 pureTabs = hideState initialState statefulTabs
statefulTab1 :: Spec State {} Action statefulTabs :: Spec State {} Action
statefulTab1 = statefulTabs =
Tab.tabs _tablens _tabAction $ fromFoldable [ Tuple "Doc View" docPageSpec Tab.tabs _tablens _tabAction $ fromFoldable [ Tuple "Documents" docPageSpec
, Tuple "Author View" authorPageSpec , Tuple "Authors" authorPageSpec
, Tuple "Source View" sourcePageSpec , Tuple "Sources" sourcePageSpec
, Tuple "Terms View" termsPageSpec , Tuple "Terms" termsPageSpec
] ]
docPageSpec :: Spec State {} Action docPageSpec :: Spec State {} Action
......
module Gargantext.Pages.Corpus.Tabs.States where module Gargantext.Pages.Corpus.Tabs.States where
import Data.Lens (Lens', lens) import Data.Lens (Lens', lens)
import Gargantext.Pages.Corpus.Tabs.Documents as DV import Gargantext.Pages.Corpus.Tabs.Documents as D
import Gargantext.Pages.Corpus.Tabs.Sources as SV import Gargantext.Pages.Corpus.Tabs.Sources as S
import Gargantext.Pages.Corpus.Tabs.Authors as AV import Gargantext.Pages.Corpus.Tabs.Authors as A
import Gargantext.Pages.Corpus.Tabs.Terms as TV import Gargantext.Pages.Corpus.Tabs.Terms as T
import Gargantext.Components.Tab as Tab import Gargantext.Components.Tab as Tab
type State = type State =
{ docview :: DV.State { docsView :: D.State
, authorview :: AV.State , authorsView :: A.State
, sourceview :: SV.State , sourcesView :: S.State
, termsview :: TV.State , termsView :: T.State
, activeTab :: Int , activeTab :: Int
} }
initialState :: State initialState :: State
initialState = initialState =
{ docview : DV.initialState { docsView : D.initialState
, authorview : AV.initialState , authorsView : A.initialState
, sourceview : SV.initialState , sourcesView : S.initialState
, termsview : TV.initialState , termsView : T.initialState
, activeTab : 0 , activeTab : 0
} }
_doclens :: Lens' State DV.State _doclens :: Lens' State D.State
_doclens = lens (\s -> s.docview) (\s ss -> s {docview = ss}) _doclens = lens (\s -> s.docsView) (\s ss -> s {docsView = ss})
_authorlens :: Lens' State AV.State _authorlens :: Lens' State A.State
_authorlens = lens (\s -> s.authorview) (\s ss -> s {authorview = ss}) _authorlens = lens (\s -> s.authorsView) (\s ss -> s {authorsView = ss})
_sourcelens :: Lens' State SV.State _sourcelens :: Lens' State S.State
_sourcelens = lens (\s -> s.sourceview) (\s ss -> s {sourceview = ss}) _sourcelens = lens (\s -> s.sourcesView) (\s ss -> s {sourcesView = ss})
_termslens :: Lens' State TV.State _termslens :: Lens' State T.State
_termslens = lens (\s -> s.termsview) (\s ss -> s {termsview = ss}) _termslens = lens (\s -> s.termsView) (\s ss -> s {termsView = ss})
_tablens :: Lens' State Tab.State _tablens :: Lens' State Tab.State
_tablens = lens (\s -> s.activeTab) (\s ss -> s {activeTab = ss}) _tablens = lens (\s -> s.activeTab) (\s ss -> s {activeTab = ss})
...@@ -9,6 +9,7 @@ import Gargantext.Pages.Layout.Specs.AddCorpus as AC ...@@ -9,6 +9,7 @@ import Gargantext.Pages.Layout.Specs.AddCorpus as AC
import Gargantext.Pages.Corpus as Corpus import Gargantext.Pages.Corpus as Corpus
import Gargantext.Pages.Corpus.Document as Document import Gargantext.Pages.Corpus.Document as Document
import Gargantext.Pages.Corpus.Tabs.Documents as D import Gargantext.Pages.Corpus.Tabs.Documents as D
import Gargantext.Pages.Corpus.Tabs.Actions as TabsA
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
...@@ -38,7 +39,7 @@ dispatchAction dispatcher _ AddCorpus = do ...@@ -38,7 +39,7 @@ 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.DocviewA $ D.UpdateNodeId 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
......
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