Commit f2addfc7 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FOREST] Search form, removing mkEffectFn1

parent a417fb7f
...@@ -7,7 +7,6 @@ import Data.Set as Set ...@@ -7,7 +7,6 @@ import Data.Set as Set
import Data.Tuple (fst) import Data.Tuple (fst)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Effect.Uncurried (mkEffectFn1)
import FFI.Simple ((..)) import FFI.Simple ((..))
import Reactix as R import Reactix as R
import Reactix.DOM.HTML (text, button, div, input, span, ul, li, a, option, text) import Reactix.DOM.HTML (text, button, div, input, span, ul, li, a, option, text)
...@@ -79,10 +78,9 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged ...@@ -79,10 +78,9 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
[ ul {} $ map ( \org' -> li {} [ ul {} $ map ( \org' -> li {}
[ input { type: "checkbox" [ input { type: "checkbox"
, checked: isInFilters org' curFilters , checked: isInFilters org' curFilters
, on: {click: mkEffectFn1 , on: {change: \_ -> setFilters
$ \_ -> setFilters $ const
$ const $ updateFilter org' curFilters
$ updateFilter org' curFilters
} }
} }
, text $ " " <> show org' , text $ " " <> show org'
...@@ -121,8 +119,14 @@ updateFilter org (Just (HAL_IMT { imtOrgs})) = ...@@ -121,8 +119,14 @@ updateFilter org (Just (HAL_IMT { imtOrgs})) =
} }
where where
imtOrgs' = if Set.member org imtOrgs imtOrgs' = if Set.member org imtOrgs
then Set.delete org imtOrgs then
else Set.insert org imtOrgs if org == All_IMT
then Set.empty
else Set.delete org imtOrgs
else
if org == All_IMT
then Set.fromFoldable allIMTorgs
else Set.insert org imtOrgs
updateFilter org _ = Just $ HAL_IMT { imtOrgs: imtOrgs', structIds: Set.empty} updateFilter org _ = Just $ HAL_IMT { imtOrgs: imtOrgs', structIds: Set.empty}
where where
...@@ -141,8 +145,8 @@ databaseInput (db /\ setDB) (_ /\ setFilters) (_ /\ setOrg) dbs = ...@@ -141,8 +145,8 @@ databaseInput (db /\ setDB) (_ /\ setFilters) (_ /\ setOrg) dbs =
$ const $ const
$ readDatabase $ readDatabase
$ e .. "target" .. "value") $ e .. "target" .. "value")
*> (setFilters $ const Nothing)
*> (setOrg $ const Nothing) *> (setOrg $ const Nothing)
*> (setFilters $ const Nothing)
} }
} (liItem <$> dbs) } (liItem <$> dbs)
] ]
...@@ -156,11 +160,11 @@ langInput (lang /\ setLang) langs = ...@@ -156,11 +160,11 @@ langInput (lang /\ setLang) langs =
div { className: "form-group" } div { className: "form-group" }
[ text "with lang" [ text "with lang"
, R2.select { className: "form-control" , R2.select { className: "form-control"
, onChange: mkEffectFn1 , on: { change: \e -> setLang
$ \e -> setLang $ const
$ const $ readLang
$ readLang $ e .. "target" .. "value"
$ e .. "target" .. "value" }
} (liItem <$> langs) } (liItem <$> langs)
] ]
where where
...@@ -172,11 +176,11 @@ orgInput (org /\ setOrg) orgs = ...@@ -172,11 +176,11 @@ orgInput (org /\ setOrg) orgs =
div { className: "form-group" } div { className: "form-group" }
[ text "filter with organization: " [ text "filter with organization: "
, R2.select { className: "form-control" , R2.select { className: "form-control"
, onChange: mkEffectFn1 , on: { change: \e -> setOrg
$ \e -> setOrg $ const
$ const $ readOrg
$ readOrg $ e .. "target" .. "value"
$ e .. "target" .. "value" }
} (liItem <$> orgs) } (liItem <$> orgs)
] ]
where where
...@@ -188,8 +192,8 @@ filterInput (term /\ setTerm) = ...@@ -188,8 +192,8 @@ filterInput (term /\ setTerm) =
div {className: ""} [ input { defaultValue: term div {className: ""} [ input { defaultValue: term
, className: "form-control" , className: "form-control"
, type: "text" , type: "text"
, onChange: mkEffectFn1 $ \e -> setTerm $ const $ e .. "target" .. "value" , on: { change: \e -> setTerm $ const $ e .. "target" .. "value"}
, placeHolder : "Filter with struct_Ids as integer" } , placeholder : "Filter with struct_Ids as integer" }
] ]
...@@ -199,13 +203,9 @@ searchInput (term /\ setTerm) = ...@@ -199,13 +203,9 @@ searchInput (term /\ setTerm) =
[ input { defaultValue: term [ input { defaultValue: term
, className: "form-control" , className: "form-control"
, type: "text" , type: "text"
, onChange , on: { change : \e -> setTerm $ const $ e .. "target" .. "value" }
, placeHolder: "Your Query here" } , placenolder: "Your Query here" }
] ]
where
onChange = mkEffectFn1 $ \e -> setTerm
$ const
$ e .. "target" .. "value"
submitButton :: R.State (Maybe Database) submitButton :: R.State (Maybe Database)
...@@ -219,11 +219,11 @@ submitButton (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_ ...@@ -219,11 +219,11 @@ submitButton (database /\ _) (term /\ _) (lang /\ _) (org/\_) (filters /\ _) (_
R.fragment [ div { className : "" } [] R.fragment [ div { className : "" } []
, button { className: "btn btn-primary text-center" , button { className: "btn btn-primary text-center"
, type: "button" , type: "button"
, onClick: click , on: {change: click}
} [ text "Search" ] } [ text "Search" ]
] ]
where where
click = mkEffectFn1 $ \_ -> do click = \_ -> do
case term of case term of
"" -> setSearch $ const Nothing "" -> setSearch $ const Nothing
_ -> setSearch $ const $ Just { database, lang, filters, term, org} _ -> setSearch $ const $ Just { database, lang, filters, term, org}
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