Remove docsView from global state

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