diff --git a/src/Gargantext/Components/NgramsTable.purs b/src/Gargantext/Components/NgramsTable.purs index 551dcd01c3a28bb0070c9e3631696d64388baa7d..4ca8e5d4e02f59b0b8c8ce4cea9d46e4c4cb6589 100644 --- a/src/Gargantext/Components/NgramsTable.purs +++ b/src/Gargantext/Components/NgramsTable.purs @@ -30,7 +30,8 @@ import React (ReactElement) import React.DOM (a, i, input, li, span, text, ul) import React.DOM.Props (_type, checked, className, onChange, onClick, style) import React.DOM.Props as DOM -import Thermite (PerformAction, Render, Spec, modifyState_, simpleSpec) +import Thermite as Thermite +import Thermite (modifyState_) import Gargantext.Types ( CTabNgramType, OrderBy(..), TabType, TermList(..), readTermList , readTermSize, termLists, termSizes) @@ -181,14 +182,6 @@ data Action' | ToggleChild' (Maybe NgramsTerm) NgramsTerm | 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 = ( session :: Session , tabNgramType :: CTabNgramType @@ -205,13 +198,21 @@ loadedNgramsTableCpt = R.hooksComponent "G.C.NgramsTable.loadedNgramsTable" cpt state <- useNgramsReducer (initialState versioned) pure $ R.fragment [] -ngramsTableSpec :: Session -> CTabNgramType -> R2.Setter PageParams -> Spec State (Record LoadedNgramsTableProps) Action -ngramsTableSpec session ntype setPath = simpleSpec performAction render + useNgramsReducer :: State -> R.Hooks (R.Reducer State Action') + 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 setParentResetChildren :: Maybe NgramsTerm -> State -> State setParentResetChildren p = _ { ngramsParent = p, ngramsChildren = mempty } - performAction :: PerformAction State (Record LoadedNgramsTableProps) Action + performAction :: Thermite.PerformAction State (Record LoadedNgramsTableProps) Action performAction (SetParentResetChildren p) _ _ = modifyState_ $ setParentResetChildren p performAction (ToggleChild b c) _ _ = @@ -242,7 +243,7 @@ ngramsTableSpec session ntype setPath = simpleSpec performAction render where pt = addNewNgram ntype ngram CandidateTerm - render :: Render State (Record LoadedNgramsTableProps) Action + render :: Thermite.Render State (Record LoadedNgramsTableProps) Action render dispatch { path: pageParams , loaded: Versioned { data: initTable } } { ngramsTablePatch, ngramsParent, ngramsChildren } diff --git a/src/Gargantext/Sessions.purs b/src/Gargantext/Sessions.purs index d3696d46a211fae25346de7ad43b75532bb9d59e..88adeb25f21ffe72dfa9b8745fdef168544b6b07 100644 --- a/src/Gargantext/Sessions.purs +++ b/src/Gargantext/Sessions.purs @@ -118,7 +118,7 @@ useSessions :: R.Hooks (R2.Reductor Sessions Action) useSessions = R2.useReductor actAndSave (const loadSessions) unit where 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 sid (Sessions {sessions:ss}) = Seq.head (Seq.filter f ss) where diff --git a/src/Gargantext/Utils/Reactix.purs b/src/Gargantext/Utils/Reactix.purs index cda76c24fe9cbf227299517e33fd6a6b3cf5e20d..c81c56dd9ed056ac8ec162bdd8a605b5c0071435 100644 --- a/src/Gargantext/Utils/Reactix.purs +++ b/src/Gargantext/Utils/Reactix.purs @@ -29,7 +29,7 @@ newtype Point = Point { x :: Number, y :: Number } -- a setter function, for useState type Setter t = (t -> t) -> Effect Unit -- 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 -- | buff (v.) to polish @@ -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 f i j = 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 -- | initialiser function and argument