Remove docsView from global state

parent 24191699
module Gargantext.Pages.Corpus.Tabs.Actions where module Gargantext.Pages.Corpus.Tabs.Actions where
import Data.Lens (Prism', prism) import Data.Lens (Prism', prism)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Void (Void)
import Gargantext.Pages.Corpus.Tabs.Documents as DV
import Gargantext.Pages.Corpus.Tabs.Ngrams.NgramsTable as NG
import Gargantext.Components.Tab as Tab import Gargantext.Components.Tab as Tab
data Action data Action
= DocViewA DV.Action -- = Void = TabAction Tab.Action -- = ChangeTab which is only used locally
| TabViewA Tab.Action -- = ChangeTab which is only used locally
_docAction :: Prism' Action DV.Action
_docAction = prism DocViewA \ action ->
case action of
DocViewA laction -> Right laction
_-> Left action
_tabAction :: Prism' Action Tab.Action _TabAction :: Prism' Action Tab.Action
_tabAction = prism TabViewA \ action -> _TabAction = prism TabAction \ action ->
case action of case action of
TabViewA laction -> Right laction TabAction laction -> Right laction
_-> Left action _-> Left action
...@@ -38,7 +38,7 @@ import Gargantext.Pages.Corpus.Tabs.Types (CorpusInfo(..), Props) ...@@ -38,7 +38,7 @@ import Gargantext.Pages.Corpus.Tabs.Types (CorpusInfo(..), Props)
import Gargantext.Utils.DecodeMaybe ((.|)) import Gargantext.Utils.DecodeMaybe ((.|))
import React.DOM (a, br', button, div, i, input, p, text) import React.DOM (a, br', button, div, i, input, p, text)
import React.DOM.Props (_type, className, href, name, onClick, placeholder, style, value) import React.DOM.Props (_type, className, href, name, onClick, placeholder, style, value)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState_, simpleSpec) import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState_, simpleSpec, hideState)
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- TODO: Pagination Details are not available from the BackEnd -- TODO: Pagination Details are not available from the BackEnd
-- TODO: Search is pending -- TODO: Search is pending
...@@ -51,6 +51,11 @@ type State = ...@@ -51,6 +51,11 @@ type State =
{ documentIdsToDelete :: Set Int { documentIdsToDelete :: Set Int
} }
initialState :: State
initialState =
{ documentIdsToDelete: mempty
}
data Action data Action
= MarkFavorites (Array Int) = MarkFavorites (Array Int)
| ToggleDocumentToDelete Int | ToggleDocumentToDelete Int
...@@ -134,6 +139,9 @@ filterSpec = simpleSpec defaultPerformAction render ...@@ -134,6 +139,9 @@ filterSpec = simpleSpec defaultPerformAction render
, input [] , input []
]] ]]
docViewSpec :: Spec {} Props Void
docViewSpec = hideState (const initialState) layoutDocview
-- | Main layout of the Documents Tab of a Corpus -- | Main layout of the Documents Tab of a Corpus
layoutDocview :: Spec State Props Action layoutDocview :: Spec State Props Action
layoutDocview = simpleSpec performAction render layoutDocview = simpleSpec performAction render
......
...@@ -6,8 +6,8 @@ import Data.List (fromFoldable) ...@@ -6,8 +6,8 @@ import Data.List (fromFoldable)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Gargantext.Pages.Corpus.Tabs.Types (Props) import Gargantext.Pages.Corpus.Tabs.Types (Props)
import Gargantext.Pages.Corpus.Tabs.States (State(), _doclens, _tablens, initialState) import Gargantext.Pages.Corpus.Tabs.States (State(), initialState, _activeTab)
import Gargantext.Pages.Corpus.Tabs.Actions (Action(), _docAction, _tabAction) import Gargantext.Pages.Corpus.Tabs.Actions (Action(), _TabAction)
import Gargantext.Pages.Corpus.Tabs.Documents as DV import Gargantext.Pages.Corpus.Tabs.Documents as DV
import Gargantext.Pages.Corpus.Tabs.Ngrams.NgramsTable as NV import Gargantext.Pages.Corpus.Tabs.Ngrams.NgramsTable as NV
...@@ -20,35 +20,16 @@ import Thermite (Spec, focus, hideState, noState, cmapProps) ...@@ -20,35 +20,16 @@ import Thermite (Spec, focus, hideState, noState, cmapProps)
statefulTabs :: Spec State Props Action statefulTabs :: Spec State Props Action
statefulTabs = statefulTabs =
Tab.tabs _tablens _tabAction $ fromFoldable [ Tuple "Documents" docPageSpec Tab.tabs _activeTab _TabAction $ fromFoldable
, Tuple "Authors" authorPageSpec [ Tuple "Documents" $ noState DV.docViewSpec
, Tuple "Sources" sourcePageSpec , Tuple "Authors" $ ngramsViewSpec {mode: NV.Authors}
, Tuple "Institutes" institutesPageSpec , Tuple "Sources" $ ngramsViewSpec {mode: NV.Sources}
, Tuple "Terms" termsPageSpec , Tuple "Institutes" $ ngramsViewSpec {mode: NV.Institutes}
, Tuple "Trash" trashPageSpec , Tuple "Terms" $ ngramsViewSpec {mode: NV.Terms}
] , Tuple "Trash" $ noState DV.docViewSpec -- TODO pass-in trash mode
]
docPageSpec :: Spec State Props Action
docPageSpec = focus _doclens _docAction DV.layoutDocview
ngramsViewSpec :: {mode :: NV.Mode} -> Spec State Props Action ngramsViewSpec :: {mode :: NV.Mode} -> Spec State Props Action
ngramsViewSpec {mode} = ngramsViewSpec {mode} =
cmapProps (\{loaded, path, dispatch} -> {mode,loaded,path, dispatch}) cmapProps (\{loaded, path, dispatch} -> {mode,loaded,path, dispatch})
(noState NV.ngramsTableSpec) (noState NV.ngramsTableSpec)
authorPageSpec :: Spec State Props Action
authorPageSpec = ngramsViewSpec {mode: NV.Authors}
sourcePageSpec :: Spec State Props Action
sourcePageSpec = ngramsViewSpec {mode: NV.Sources}
institutesPageSpec :: Spec State Props Action
institutesPageSpec = ngramsViewSpec {mode: NV.Institutes}
termsPageSpec :: Spec State Props Action
termsPageSpec = ngramsViewSpec {mode: NV.Terms}
trashPageSpec :: Spec State Props Action
trashPageSpec = focus _doclens _docAction DV.layoutDocview
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.Prelude
import Gargantext.Pages.Corpus.Tabs.Documents as D
import Gargantext.Pages.Corpus.Tabs.Ngrams.NgramsTable as N
import Gargantext.Components.Tab as Tab import Gargantext.Components.Tab as Tab
type State = type State =
{ docsView :: D.State { activeTab :: Int
, activeTab :: Int
} }
initialState :: {} -> State initialState :: {} -> State
initialState _ = initialState _ =
{ docsView : { activeTab: 0
{ documentIdsToDelete : mempty
}
, activeTab : 0
} }
_doclens :: Lens' State D.State _activeTab :: Lens' State Tab.State
_doclens = lens (\s -> s.docsView) (\s ss -> s {docsView = ss}) _activeTab = lens _.activeTab (\s ss -> s {activeTab = ss})
_tablens :: Lens' State Tab.State
_tablens = lens (\s -> s.activeTab) (\s ss -> s {activeTab = ss})
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