Commit 801e3852 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

Merge branch 'dev-graph-explorer-ui-improvements' into 'dev'

Dev graph explorer ui improvements

See merge request !129
parents 3e4eb3d8 c4bc5fb3
...@@ -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,19 +86,32 @@ inputWithAutocompleteCpt = R.hooksComponentWithModule thisModule "inputWithAutoc ...@@ -82,19 +86,32 @@ 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
H.div { className: "list-group" } (cCpt <$> completions) )
]
where completions :: R2.Component CompletionsProps
className = "completions " <> (if completions == [] then "d-none" else "") completions = R.createElement completionsCpt
cCpt c = completionsCpt :: R.Component CompletionsProps
H.button { type: "button" completionsCpt = R.hooksComponentWithModule thisModule "completions" cpt
, className: "list-group-item" where
, on: { click: onClick c } } [ H.text c ] cpt { completionsS: cmpls /\ setCompletions
onClick c _ = do , onAutocompleteClick
setState $ const c , state: _ /\ setState } _ =
onAutocompleteClick c pure $ H.div { className }
[
H.div { className: "list-group" } (cCpt <$> cmpls)
]
where
className = "completions " <> (if cmpls == [] then "d-none" else "")
cCpt c =
H.button { type: "button"
, className: "list-group-item"
, on: { click: onClick c } } [ H.text c ]
onClick c _ = do
setState $ const c
onAutocompleteClick 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