Hide the state of NgramsItem

parent 8c3e1b1f
...@@ -2,17 +2,21 @@ module Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsItem where ...@@ -2,17 +2,21 @@ module Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsItem where
import Prelude import Prelude
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype, unwrap)
import Data.Lens.Iso (re)
import Data.Lens.Iso.Newtype (_Newtype)
import React (ReactElement) import React (ReactElement)
import React.DOM (input, span, td, text, tr) import React.DOM (input, span, td, text, tr)
import React.DOM.Props (_type, checked, className, onChange, style, title) import React.DOM.Props (_type, checked, className, onChange, style, title)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec) import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec, hide, focusState)
import Gargantext.Utils (getter, setter) import Gargantext.Utils (getter, setter)
newtype State = State newtype State = State
{ term :: Term { term :: Term
} }
derive instance newtypeState :: Newtype State _
initialState :: State initialState :: State
initialState = State {term : Term {id : 10, term : "hello", occurrence : 10, _type : None, children : []}} initialState = State {term : Term {id : 10, term : "hello", occurrence : 10, _type : None, children : []}}
...@@ -40,8 +44,10 @@ performAction (SetMap b) _ _ = void do ...@@ -40,8 +44,10 @@ performAction (SetMap b) _ _ = void do
performAction (SetStop b) _ _ = void do performAction (SetStop b) _ _ = void do
modifyState \(State s) -> State s {term = setter (_{_type = (if b then StopTerm else None)}) s.term} modifyState \(State s) -> State s {term = setter (_{_type = (if b then StopTerm else None)}) s.term}
ngramsItemSpec :: Spec State {} Action ngramsItemSpec :: Spec {} {} Void
ngramsItemSpec = simpleSpec performAction render ngramsItemSpec = hide (unwrap initialState) $
focusState (re _Newtype) $
simpleSpec performAction render
where where
render :: Render State {} Action render :: Render State {} Action
render dispatch _ (State state) _ = render dispatch _ (State state) _ =
......
...@@ -15,12 +15,12 @@ import Prelude (class Eq, class Ord, class Show, map, show, void, ($), (*), (+), ...@@ -15,12 +15,12 @@ import Prelude (class Eq, class Ord, class Show, map, show, void, ($), (*), (+),
import React (ReactElement) import React (ReactElement)
import React.DOM hiding (style, map) import React.DOM hiding (style, map)
import React.DOM.Props (_id, _type, className, href, name, onChange, onClick, onInput, placeholder, scope, selected, style, value) import React.DOM.Props (_id, _type, className, href, name, onChange, onClick, onInput, placeholder, scope, selected, style, value)
import Thermite (PerformAction, Spec, _render, cotransform, focus, foreach, modifyState, withState, focusState, hide) import Thermite (PerformAction, Spec, _render, cotransform, focus, foreach, modifyState, focusState, hide)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
newtype State = State newtype State = State
{ items :: List NI.State { items :: List {}
, search :: String , search :: String
, selectString :: String , selectString :: String
, totalPages :: Int , totalPages :: Int
, currentPage :: Int , currentPage :: Int
...@@ -31,26 +31,26 @@ newtype State = State ...@@ -31,26 +31,26 @@ newtype State = State
derive instance newtypeState :: Newtype State _ derive instance newtypeState :: Newtype State _
initialState :: State initialState :: State
initialState = State { items : toUnfoldable [NI.initialState] initialState = State { items : toUnfoldable [{}]
, search : "" , search : ""
, selectString : "" , selectString : ""
,totalPages : 10 , totalPages : 10
, currentPage : 1 , currentPage : 1
, pageSize : PS10 , pageSize : PS10
, totalRecords : 100 , totalRecords : 100
} }
data Action data Action
= ItemAction Int NI.Action = ItemAction Int Void
| ChangeString String | ChangeString String
| SetInput String | SetInput String
| ChangePageSize PageSizes | ChangePageSize PageSizes
| ChangePage Int | ChangePage Int
_itemsList :: Lens' State (List NI.State) _itemsList :: Lens' State (List {})
_itemsList = lens (\(State s) -> s.items) (\(State s) v -> State s { items = v }) _itemsList = lens (\(State s) -> s.items) (\(State s) v -> State s { items = v })
_ItemAction :: Prism' Action (Tuple Int NI.Action) _ItemAction :: Prism' Action (Tuple Int Void)
_ItemAction = prism (uncurry ItemAction) \ta -> _ItemAction = prism (uncurry ItemAction) \ta ->
case ta of case ta of
ItemAction i a -> Right (Tuple i a) ItemAction i a -> Right (Tuple i a)
...@@ -153,13 +153,14 @@ tableSpec = over _render \render dispatch p (State s) c -> ...@@ -153,13 +153,14 @@ tableSpec = over _render \render dispatch p (State s) c ->
] ]
ngramsTableSpec :: Spec {} {} Void ngramsTableSpec :: Spec {} {} Void
ngramsTableSpec = hide (unwrap initialState) $ ngramsTableSpec =
focusState (re _Newtype) $ hide (unwrap initialState) $
container $ fold focusState (re _Newtype) $
[ tableSpec $ withState \st -> container $
focus _itemsList _ItemAction $ tableSpec $
foreach \_ -> NI.ngramsItemSpec focus _itemsList _ItemAction $
] foreach $ \ _ ->
NI.ngramsItemSpec
container :: forall state props action. Spec state props action -> Spec state props action container :: forall state props action. Spec state props action -> Spec state props action
container = over _render \render d p s c -> container = over _render \render d p s c ->
......
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