Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
15e0b58f
Commit
15e0b58f
authored
Feb 08, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[search] small refactoring of inputWithAutocomplete
parent
a86747d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
27 deletions
+44
-27
Search.purs
src/Gargantext/Components/GraphExplorer/Search.purs
+1
-1
InputWithAutocomplete.purs
src/Gargantext/Components/InputWithAutocomplete.purs
+43
-26
No files found.
src/Gargantext/Components/GraphExplorer/Search.purs
View file @
15e0b58f
...
...
@@ -49,7 +49,7 @@ sizeButtonCpt = R.hooksComponentWithModule thisModule "nodeSearchControl" cpt
[ inputWithAutocomplete { autocompleteSearch: autocompleteSearch graph
, onAutocompleteClick: \s -> triggerSearch graph s multiSelectEnabled selectedNodeIds
, onEnterPress: \s -> triggerSearch graph s multiSelectEnabled selectedNodeIds
, state: search }
, state: search }
[]
, H.div { className: "btn input-group-addon"
, on: { click: \_ -> triggerSearch graph search' multiSelectEnabled selectedNodeIds }
}
...
...
src/Gargantext/Components/InputWithAutocomplete.purs
View file @
15e0b58f
...
...
@@ -13,6 +13,7 @@ import Reactix.DOM.HTML as H
import Gargantext.Utils.Reactix as R2
thisModule :: String
thisModule = "Gargantext.Components.InputWithAutocomplete"
...
...
@@ -26,29 +27,32 @@ type Props =
, state :: R.State String
)
inputWithAutocomplete :: R
ecord Props -> R.Element
inputWithAutocomplete
props = R.createElement inputWithAutocompleteCpt props []
inputWithAutocomplete :: R
2.Component Props
inputWithAutocomplete
= R.createElement inputWithAutocompleteCpt
inputWithAutocompleteCpt :: R.Component Props
inputWithAutocompleteCpt = R.hooksComponentWithModule thisModule "inputWithAutocomplete" cpt
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
completions <- R.useState' $ autocompleteSearch state'
completions
S
<- R.useState' $ autocompleteSearch state'
pure $
H.span { className: "input-with-autocomplete" }
[
completions
Cpt completions
completions
{ completionsS, onAutocompleteClick, state } []
, H.input { type: "text"
, ref: inputRef
, className: "form-control"
, value: state'
, on: { blur: onBlur completions
, focus: onFocus completions
, input: onInput completions
, change: onInput completions
, keyUp: onInputKeyUp inputRef completions } }
, on: { blur: onBlur completions
S
, focus: onFocus completions
S
, input: onInput completions
S
, change: onInput completions
S
, keyUp: onInputKeyUp inputRef completions
S
} }
]
where
...
...
@@ -82,19 +86,32 @@ inputWithAutocompleteCpt = R.hooksComponentWithModule thisModule "inputWithAutoc
else
pure $ unit
completionsCpt :: R.State Completions -> R.Element
completionsCpt (completions /\ setCompletions) =
H.div { className }
[
H.div { className: "list-group" } (cCpt <$> completions)
]
where
className = "completions " <> (if completions == [] 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
type CompletionsProps = (
completionsS :: R.State Completions
, 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 <$> 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment