Commit 15e0b58f authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[search] small refactoring of inputWithAutocomplete

parent a86747d1
...@@ -49,7 +49,7 @@ sizeButtonCpt = R.hooksComponentWithModule thisModule "nodeSearchControl" cpt ...@@ -49,7 +49,7 @@ sizeButtonCpt = R.hooksComponentWithModule thisModule "nodeSearchControl" cpt
[ inputWithAutocomplete { autocompleteSearch: autocompleteSearch graph [ inputWithAutocomplete { autocompleteSearch: autocompleteSearch graph
, onAutocompleteClick: \s -> triggerSearch graph s multiSelectEnabled selectedNodeIds , onAutocompleteClick: \s -> triggerSearch graph s multiSelectEnabled selectedNodeIds
, onEnterPress: \s -> triggerSearch graph s multiSelectEnabled selectedNodeIds , onEnterPress: \s -> triggerSearch graph s multiSelectEnabled selectedNodeIds
, state: search } , state: search } []
, H.div { className: "btn input-group-addon" , H.div { className: "btn input-group-addon"
, on: { click: \_ -> triggerSearch graph search' multiSelectEnabled selectedNodeIds } , on: { click: \_ -> triggerSearch graph search' multiSelectEnabled selectedNodeIds }
} }
......
...@@ -13,6 +13,7 @@ import Reactix.DOM.HTML as H ...@@ -13,6 +13,7 @@ import Reactix.DOM.HTML as H
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
thisModule :: String
thisModule = "Gargantext.Components.InputWithAutocomplete" thisModule = "Gargantext.Components.InputWithAutocomplete"
...@@ -26,29 +27,32 @@ type Props = ...@@ -26,29 +27,32 @@ type Props =
, state :: R.State String , state :: R.State String
) )
inputWithAutocomplete :: Record Props -> R.Element inputWithAutocomplete :: R2.Component Props
inputWithAutocomplete props = R.createElement inputWithAutocompleteCpt props [] inputWithAutocomplete = R.createElement inputWithAutocompleteCpt
inputWithAutocompleteCpt :: R.Component Props inputWithAutocompleteCpt :: R.Component Props
inputWithAutocompleteCpt = R.hooksComponentWithModule thisModule "inputWithAutocomplete" cpt inputWithAutocompleteCpt = R.hooksComponentWithModule thisModule "inputWithAutocomplete" cpt
where where
cpt props@{autocompleteSearch, onAutocompleteClick, onEnterPress, state: state@(state' /\ setState)} _ = do cpt props@{ autocompleteSearch
, onAutocompleteClick
, onEnterPress
, state: state@(state' /\ setState) } _ = do
inputRef <- R.useRef null inputRef <- R.useRef null
completions <- R.useState' $ autocompleteSearch state' completionsS <- R.useState' $ autocompleteSearch state'
pure $ pure $
H.span { className: "input-with-autocomplete" } H.span { className: "input-with-autocomplete" }
[ [
completionsCpt completions completions { completionsS, onAutocompleteClick, state } []
, H.input { type: "text" , H.input { type: "text"
, ref: inputRef , ref: inputRef
, className: "form-control" , className: "form-control"
, value: state' , value: state'
, on: { blur: onBlur completions , on: { blur: onBlur completionsS
, focus: onFocus completions , focus: onFocus completionsS
, input: onInput completions , input: onInput completionsS
, change: onInput completions , change: onInput completionsS
, keyUp: onInputKeyUp inputRef completions } } , keyUp: onInputKeyUp inputRef completionsS } }
] ]
where where
...@@ -82,14 +86,27 @@ inputWithAutocompleteCpt = R.hooksComponentWithModule thisModule "inputWithAutoc ...@@ -82,14 +86,27 @@ inputWithAutocompleteCpt = R.hooksComponentWithModule thisModule "inputWithAutoc
else else
pure $ unit pure $ unit
completionsCpt :: R.State Completions -> R.Element type CompletionsProps = (
completionsCpt (completions /\ setCompletions) = completionsS :: R.State Completions
H.div { className } , onAutocompleteClick :: String -> Effect Unit
, state :: R.State String
)
completions :: R2.Component CompletionsProps
completions = R.createElement completionsCpt
completionsCpt :: R.Component CompletionsProps
completionsCpt = R.hooksComponentWithModule thisModule "completions" cpt
where
cpt { completionsS: cmpls /\ setCompletions
, onAutocompleteClick
, state: _ /\ setState } _ =
pure $ H.div { className }
[ [
H.div { className: "list-group" } (cCpt <$> completions) H.div { className: "list-group" } (cCpt <$> cmpls)
] ]
where where
className = "completions " <> (if completions == [] then "d-none" else "") className = "completions " <> (if cmpls == [] then "d-none" else "")
cCpt c = cCpt c =
H.button { type: "button" H.button { type: "button"
......
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