Commit 005aaa67 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch '347-dev-search-enter-fix' of...

Merge branch '347-dev-search-enter-fix' of ssh://gitlab.iscpif.fr:20022/gargantext/purescript-gargantext into dev
parents 3e428833 250453ce
...@@ -3,13 +3,13 @@ module Gargantext.Components.InputWithAutocomplete where ...@@ -3,13 +3,13 @@ module Gargantext.Components.InputWithAutocomplete where
import Prelude import Prelude
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, null, toMaybe) import Data.Nullable (Nullable, null, toMaybe)
import Data.Tuple.Nested ((/\))
import DOM.Simple as DOM import DOM.Simple as DOM
import DOM.Simple.Event as DE import DOM.Simple.Event as DE
import Effect (Effect) import Effect (Effect)
import Effect.Timer (setTimeout) import Effect.Timer (setTimeout)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import React.SyntheticEvent as E
import Toestand as T import Toestand as T
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
...@@ -31,7 +31,6 @@ type Props = ...@@ -31,7 +31,6 @@ type Props =
inputWithAutocomplete :: R2.Component Props inputWithAutocomplete :: R2.Component Props
inputWithAutocomplete = R.createElement inputWithAutocompleteCpt inputWithAutocomplete = R.createElement inputWithAutocompleteCpt
inputWithAutocompleteCpt :: R.Component Props inputWithAutocompleteCpt :: R.Component Props
inputWithAutocompleteCpt = here.component "inputWithAutocomplete" cpt inputWithAutocompleteCpt = here.component "inputWithAutocomplete" cpt
where where
...@@ -44,7 +43,7 @@ inputWithAutocompleteCpt = here.component "inputWithAutocomplete" cpt ...@@ -44,7 +43,7 @@ inputWithAutocompleteCpt = here.component "inputWithAutocomplete" cpt
inputRef <- R.useRef null inputRef <- R.useRef null
completions <- T.useBox $ autocompleteSearch state' completions <- T.useBox $ autocompleteSearch state'
let onFocus completions e = T.write_ (autocompleteSearch state') completions let onFocus completions' _ = T.write_ (autocompleteSearch state') completions'
pure $ pure $
H.span { className: "input-with-autocomplete " <> classes } H.span { className: "input-with-autocomplete " <> classes }
...@@ -69,7 +68,7 @@ inputWithAutocompleteCpt = here.component "inputWithAutocomplete" cpt ...@@ -69,7 +68,7 @@ inputWithAutocompleteCpt = here.component "inputWithAutocomplete" cpt
-- handles automatic autocomplete search, otherwise I'd have to hide it -- handles automatic autocomplete search, otherwise I'd have to hide it
-- in various different places (i.e. carefully handle all possible -- in various different places (i.e. carefully handle all possible
-- events where blur happens and autocomplete should hide). -- events where blur happens and autocomplete should hide).
onBlur completions e = setTimeout 100 $ do onBlur completions _ = setTimeout 100 $ do
T.write_ [] completions T.write_ [] completions
onInput completions e = do onInput completions e = do
...@@ -77,7 +76,7 @@ inputWithAutocompleteCpt = here.component "inputWithAutocomplete" cpt ...@@ -77,7 +76,7 @@ inputWithAutocompleteCpt = here.component "inputWithAutocomplete" cpt
T.write_ val state T.write_ val state
T.write_ (autocompleteSearch val) completions T.write_ (autocompleteSearch val) completions
onInputKeyUp :: R.Ref (Nullable DOM.Element) -> DE.KeyboardEvent -> Effect Unit onInputKeyUp :: R.Ref (Nullable DOM.Element) -> DE.KeyboardEvent -> Effect Boolean
onInputKeyUp inputRef e = do onInputKeyUp inputRef e = do
if DE.key e == "Enter" then do if DE.key e == "Enter" then do
let val = R.unsafeEventValue e let val = R.unsafeEventValue e
...@@ -85,10 +84,12 @@ inputWithAutocompleteCpt = here.component "inputWithAutocomplete" cpt ...@@ -85,10 +84,12 @@ inputWithAutocompleteCpt = here.component "inputWithAutocomplete" cpt
T.write_ val state T.write_ val state
onEnterPress val onEnterPress val
case mInput of case mInput of
Nothing -> pure unit Nothing -> pure false
Just input -> R2.blur input Just input -> do
R2.blur input
pure false
else else
pure $ unit pure $ false
type CompletionsProps = type CompletionsProps =
( completions :: T.Box Completions ( completions :: T.Box Completions
......
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