Make the state/action more focused for corpusHeaderSpec

parent ba5cceb9
...@@ -11,8 +11,8 @@ import Data.Tuple (Tuple(..)) ...@@ -11,8 +11,8 @@ 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, hide import Thermite ( Render, Spec, PerformAction, focus
, defaultPerformAction, simpleSpec, modifyState) , simpleSpec, modifyState)
-------------------------------------------------------- --------------------------------------------------------
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Components.Node (NodePoly(..)) import Gargantext.Components.Node (NodePoly(..))
...@@ -26,7 +26,8 @@ import Gargantext.Pages.Corpus.Tabs.Authors as A ...@@ -26,7 +26,8 @@ import Gargantext.Pages.Corpus.Tabs.Authors as A
import Gargantext.Pages.Corpus.Tabs.Terms as T import Gargantext.Pages.Corpus.Tabs.Terms as T
import Gargantext.Components.Tab as Tab import Gargantext.Components.Tab as Tab
------------------------------------------------------------------- -------------------------------------------------------------------
type State = { info :: Maybe (NodePoly CorpusInfo) type HeaderState = { info :: Maybe (NodePoly CorpusInfo) }
type State = { headerView :: HeaderState
, docsView :: D.State , docsView :: D.State
, authorsView :: A.State , authorsView :: A.State
, sourcesView :: S.State , sourcesView :: S.State
...@@ -35,7 +36,7 @@ type State = { info :: Maybe (NodePoly CorpusInfo) ...@@ -35,7 +36,7 @@ type State = { info :: Maybe (NodePoly CorpusInfo)
} }
initialState :: State initialState :: State
initialState = { info : Nothing initialState = { headerView : { info : Nothing }
, docsView : D.initialState , docsView : D.initialState
, authorsView : A.initialState , authorsView : A.initialState
, sourcesView : S.initialState , sourcesView : S.initialState
...@@ -44,9 +45,12 @@ initialState = { info : Nothing ...@@ -44,9 +45,12 @@ initialState = { info : Nothing
} }
------------------------------------------------------------------------ ------------------------------------------------------------------------
_info :: Lens' State (Maybe (NodePoly CorpusInfo)) _info :: forall a b. Lens' { info :: a | b } a
_info = lens (\s -> s.info) (\s ss -> s{info = ss}) _info = lens (\s -> s.info) (\s ss -> s{info = ss})
_headerView :: forall a b. Lens' { headerView :: a | b } a
_headerView = lens (\s -> s.headerView) (\s ss -> s{headerView = ss})
_doclens :: Lens' State D.State _doclens :: Lens' State D.State
_doclens = lens (\s -> s.docsView) (\s ss -> s {docsView = ss}) _doclens = lens (\s -> s.docsView) (\s ss -> s {docsView = ss})
...@@ -62,13 +66,21 @@ _termslens = lens (\s -> s.termsView) (\s ss -> s {termsView = ss}) ...@@ -62,13 +66,21 @@ _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})
------------------------------------------------------------------------ ------------------------------------------------------------------------
data Action = Load Int data HeaderAction = Load Int
data Action = HeaderA HeaderAction
| DocviewA D.Action | DocviewA D.Action
| AuthorviewA A.Action | AuthorviewA A.Action
| SourceviewA S.Action | SourceviewA S.Action
| TermsviewA T.Action | TermsviewA T.Action
| TabViewA Tab.Action | TabViewA Tab.Action
_headerAction :: Prism' Action HeaderAction
_headerAction = prism HeaderA \ action ->
case action of
HeaderA haction -> Right haction
_-> Left action
_docAction :: Prism' Action D.Action _docAction :: Prism' Action D.Action
_docAction = prism DocviewA \ action -> _docAction = prism DocviewA \ action ->
case action of case action of
...@@ -99,6 +111,12 @@ _tabAction = prism TabViewA \ action -> ...@@ -99,6 +111,12 @@ _tabAction = prism TabViewA \ action ->
TabViewA laction -> Right laction TabViewA laction -> Right laction
_-> Left action _-> Left action
_loadAction :: Prism' HeaderAction Int
_loadAction = prism Load \ action ->
case action of
Load x -> Right x
-- _-> Left action
------------------------------------------------------------------------ ------------------------------------------------------------------------
newtype CorpusInfo = CorpusInfo { title :: String newtype CorpusInfo = CorpusInfo { title :: String
, desc :: String , desc :: String
...@@ -135,12 +153,12 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where ...@@ -135,12 +153,12 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where
------------------------------------------------------------------------ ------------------------------------------------------------------------
layout :: Spec State {} Action layout :: Spec State {} Action
layout = corpusSpec <> facets layout = focus _headerView _headerAction corpusHeaderSpec <> facets
corpusSpec :: Spec State {} Action corpusHeaderSpec :: Spec HeaderState {} HeaderAction
corpusSpec = simpleSpec performAction render corpusHeaderSpec = simpleSpec performAction render
where where
render :: Render State {} Action render :: Render HeaderState {} HeaderAction
render dispatch _ state _ = render dispatch _ state _ =
[ div [className "row"] [ div [className "row"]
[ div [className "col-md-3"] [ h3 [] [text "Corpus " <> text title] ] [ div [className "col-md-3"] [ h3 [] [text "Corpus " <> text title] ]
...@@ -175,7 +193,7 @@ corpusSpec = simpleSpec performAction render ...@@ -175,7 +193,7 @@ corpusSpec = simpleSpec performAction render
------------------------------------------------------------------------ ------------------------------------------------------------------------
performAction :: PerformAction State {} Action performAction :: PerformAction HeaderState {} HeaderAction
performAction (Load nId) _ _ = do performAction (Load nId) _ _ = do
eitherInfo <- lift $ getNode nId eitherInfo <- lift $ getNode nId
_ <- case eitherInfo of _ <- case eitherInfo of
...@@ -183,11 +201,6 @@ performAction (Load nId) _ _ = do ...@@ -183,11 +201,6 @@ performAction (Load nId) _ _ = do
(Left err) -> do (Left err) -> do
logs err logs err
logs $ "Node Corpus fetched." logs $ "Node Corpus fetched."
performAction (DocviewA _) _ _ = pure unit
performAction (AuthorviewA _) _ _ = pure unit
performAction (SourceviewA _) _ _ = pure unit
performAction (TabViewA _) _ _ = pure unit
performAction (TermsviewA _) _ _ = pure unit
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
......
...@@ -38,7 +38,7 @@ dispatchAction dispatcher _ AddCorpus = do ...@@ -38,7 +38,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.Load n dispatcher $ CorpusAction $ Corpus.HeaderA $ Corpus.Load n
dispatcher $ CorpusAction $ Corpus.DocviewA $ D.LoadData n dispatcher $ CorpusAction $ Corpus.DocviewA $ D.LoadData 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