NgramsTable,useReductor: argument flip and cleaup

parent e93e14f2
...@@ -30,7 +30,8 @@ import React (ReactElement) ...@@ -30,7 +30,8 @@ import React (ReactElement)
import React.DOM (a, i, input, li, span, text, ul) import React.DOM (a, i, input, li, span, text, ul)
import React.DOM.Props (_type, checked, className, onChange, onClick, style) import React.DOM.Props (_type, checked, className, onChange, onClick, style)
import React.DOM.Props as DOM import React.DOM.Props as DOM
import Thermite (PerformAction, Render, Spec, modifyState_, simpleSpec) import Thermite as Thermite
import Thermite (modifyState_)
import Gargantext.Types import Gargantext.Types
( CTabNgramType, OrderBy(..), TabType, TermList(..), readTermList ( CTabNgramType, OrderBy(..), TabType, TermList(..), readTermList
, readTermSize, termLists, termSizes) , readTermSize, termLists, termSizes)
...@@ -181,14 +182,6 @@ data Action' ...@@ -181,14 +182,6 @@ data Action'
| ToggleChild' (Maybe NgramsTerm) NgramsTerm | ToggleChild' (Maybe NgramsTerm) NgramsTerm
| Refresh' | Refresh'
performNgramsAction :: State -> Action' -> State
performNgramsAction st (SetParentResetChildren' term) = st
performNgramsAction st (ToggleChild' b c) = st
performNgramsAction st Refresh' = st
useNgramsReducer :: State -> R.Hooks (R.Reducer State Action')
useNgramsReducer init = R.useReducer' performNgramsAction init
type Props = type Props =
( session :: Session ( session :: Session
, tabNgramType :: CTabNgramType , tabNgramType :: CTabNgramType
...@@ -205,13 +198,21 @@ loadedNgramsTableCpt = R.hooksComponent "G.C.NgramsTable.loadedNgramsTable" cpt ...@@ -205,13 +198,21 @@ loadedNgramsTableCpt = R.hooksComponent "G.C.NgramsTable.loadedNgramsTable" cpt
state <- useNgramsReducer (initialState versioned) state <- useNgramsReducer (initialState versioned)
pure $ R.fragment [] pure $ R.fragment []
ngramsTableSpec :: Session -> CTabNgramType -> R2.Setter PageParams -> Spec State (Record LoadedNgramsTableProps) Action useNgramsReducer :: State -> R.Hooks (R.Reducer State Action')
ngramsTableSpec session ntype setPath = simpleSpec performAction render useNgramsReducer init = R2.useReductor' performNgramsAction init
performNgramsAction :: Action' -> State -> Effect State
performNgramsAction (SetParentResetChildren' term) = pure -- TODO
performNgramsAction (ToggleChild' b c) = pure -- TODO
performNgramsAction Refresh' = pure -- TODO
ngramsTableSpec :: Session -> CTabNgramType -> R2.Setter PageParams -> Thermite.Spec State (Record LoadedNgramsTableProps) Action
ngramsTableSpec session ntype setPath = Thermite.simpleSpec performAction render
where where
setParentResetChildren :: Maybe NgramsTerm -> State -> State setParentResetChildren :: Maybe NgramsTerm -> State -> State
setParentResetChildren p = _ { ngramsParent = p, ngramsChildren = mempty } setParentResetChildren p = _ { ngramsParent = p, ngramsChildren = mempty }
performAction :: PerformAction State (Record LoadedNgramsTableProps) Action performAction :: Thermite.PerformAction State (Record LoadedNgramsTableProps) Action
performAction (SetParentResetChildren p) _ _ = performAction (SetParentResetChildren p) _ _ =
modifyState_ $ setParentResetChildren p modifyState_ $ setParentResetChildren p
performAction (ToggleChild b c) _ _ = performAction (ToggleChild b c) _ _ =
...@@ -242,7 +243,7 @@ ngramsTableSpec session ntype setPath = simpleSpec performAction render ...@@ -242,7 +243,7 @@ ngramsTableSpec session ntype setPath = simpleSpec performAction render
where where
pt = addNewNgram ntype ngram CandidateTerm pt = addNewNgram ntype ngram CandidateTerm
render :: Render State (Record LoadedNgramsTableProps) Action render :: Thermite.Render State (Record LoadedNgramsTableProps) Action
render dispatch { path: pageParams render dispatch { path: pageParams
, loaded: Versioned { data: initTable } } , loaded: Versioned { data: initTable } }
{ ngramsTablePatch, ngramsParent, ngramsChildren } { ngramsTablePatch, ngramsParent, ngramsChildren }
......
...@@ -118,7 +118,7 @@ useSessions :: R.Hooks (R2.Reductor Sessions Action) ...@@ -118,7 +118,7 @@ useSessions :: R.Hooks (R2.Reductor Sessions Action)
useSessions = R2.useReductor actAndSave (const loadSessions) unit useSessions = R2.useReductor actAndSave (const loadSessions) unit
where where
actAndSave :: R2.Actor Sessions Action actAndSave :: R2.Actor Sessions Action
actAndSave s a = act s a >>= saveSessions actAndSave a s = act s a >>= saveSessions
lookup :: SessionId -> Sessions -> Maybe Session lookup :: SessionId -> Sessions -> Maybe Session
lookup sid (Sessions {sessions:ss}) = Seq.head (Seq.filter f ss) where lookup sid (Sessions {sessions:ss}) = Seq.head (Seq.filter f ss) where
......
...@@ -29,7 +29,7 @@ newtype Point = Point { x :: Number, y :: Number } ...@@ -29,7 +29,7 @@ newtype Point = Point { x :: Number, y :: Number }
-- a setter function, for useState -- a setter function, for useState
type Setter t = (t -> t) -> Effect Unit type Setter t = (t -> t) -> Effect Unit
-- a reducer function living in effector, for useReductor -- a reducer function living in effector, for useReductor
type Actor t a = (t -> a -> Effect t) type Actor s a = (a -> s -> Effect s)
-- | Turns a ReactElement into aReactix Element -- | Turns a ReactElement into aReactix Element
-- | buff (v.) to polish -- | buff (v.) to polish
...@@ -158,7 +158,7 @@ type Reductor state action = Tuple state (action -> Effect Unit) ...@@ -158,7 +158,7 @@ type Reductor state action = Tuple state (action -> Effect Unit)
useReductor :: forall s a i. Actor s a -> (i -> Effect s) -> i -> R.Hooks (Reductor s a) useReductor :: forall s a i. Actor s a -> (i -> Effect s) -> i -> R.Hooks (Reductor s a)
useReductor f i j = useReductor f i j =
hook $ \_ -> hook $ \_ ->
pure $ currySecond $ tuple $ react ... "useReducer" $ args3 (mkEffectFn2 f) j (mkEffectFn1 i) pure $ currySecond $ tuple $ react ... "useReducer" $ args3 (mkEffectFn2 (flip f)) j (mkEffectFn1 i)
-- | Like `useReductor`, but takes an initial state instead of an -- | Like `useReductor`, but takes an initial state instead of an
-- | initialiser function and argument -- | initialiser function and argument
......
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