Commit 83b4876a authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngramsTable] search: delay search on button/enter press

parent 83e84d51
...@@ -32,8 +32,8 @@ searchInputCpt = here.component "searchInput" cpt ...@@ -32,8 +32,8 @@ searchInputCpt = here.component "searchInput" cpt
pure $ R2.row pure $ R2.row
[ H.div { className: "col-12" } [ H.div { className: "col-12" }
[ H.div { className: "input-group" } [ H.div { className: "input-group" }
[ searchButton { inputRef, searchQuery } [] [ searchFieldInput { inputRef, searchQuery } []
, searchFieldInput { inputRef, searchQuery } [] , searchButton { inputRef, searchQuery } []
] ]
] ]
] ]
...@@ -53,31 +53,34 @@ searchButtonCpt = here.component "searchButton" cpt where ...@@ -53,31 +53,34 @@ searchButtonCpt = here.component "searchButton" cpt where
pure $ pure $
H.div H.div
{ className: intercalate " " { className: "search-button-append input-group-append" }
[ "search-button-prepend"
, "input-group-prepend"
]
}
[ [
if searchQuery' /= "" if searchQuery' /= ""
then then
B.button R.fragment
{ variant: ButtonVariant Light [ B.button
, callback: \_ -> R2.setInputValue inputRef "" { variant: ButtonVariant Light
-- T.write "" searchQuery , callback: \_ -> do
, className: "input-group-text" R2.setInputValue inputRef ""
} T.write_ "" searchQuery
[ , className: "input-group-text" }
B.icon [ B.icon
{ name: "times" { name: "times"
, className: "text-danger" , className: "text-danger"
} }
] ]
, B.button { callback: \_ -> T.write_ (R2.getInputValue inputRef) searchQuery
, className: "input-group-text" }
[ B.icon { name: "search" }
]
]
else else
B.icon B.button { callback: \_ -> T.write_ (R2.getInputValue inputRef) searchQuery
{ name: "search" , className: "input-group-text" }
, className: "input-group-text" [ B.icon
} { name: "search" }
]
] ]
type SearchFieldInputProps = type SearchFieldInputProps =
...@@ -90,13 +93,20 @@ searchFieldInput = R.createElement searchFieldInputCpt ...@@ -90,13 +93,20 @@ searchFieldInput = R.createElement searchFieldInputCpt
searchFieldInputCpt :: R.Component SearchFieldInputProps searchFieldInputCpt :: R.Component SearchFieldInputProps
searchFieldInputCpt = here.component "searchFieldInput" cpt where searchFieldInputCpt = here.component "searchFieldInput" cpt where
cpt { inputRef, searchQuery } _ = do cpt { inputRef, searchQuery } _ = do
-- searchQuery' <- T.useLive T.unequal searchQuery
pure $ H.input { className: "form-control" pure $ H.input { className: "form-control"
-- , defaultValue: searchQuery' -- , defaultValue: searchQuery'
, name: "search" , name: "search"
, on: { input: \e -> T.write (R.unsafeEventValue e) searchQuery } , on: { keyPress: onKeyPress }
, placeholder: "Search" , placeholder: "Search"
, ref: inputRef , ref: inputRef
, type: "value" , type: "value"
} }
where
onKeyPress e = do
char <- R2.keyCode e
if char == 13 then
T.write_ (R2.getInputValue inputRef) searchQuery
else
pure unit
...@@ -608,6 +608,12 @@ foreign import _triggerEvent ...@@ -608,6 +608,12 @@ foreign import _triggerEvent
triggerEvent :: forall el. el -> String -> Effect Unit triggerEvent :: forall el. el -> String -> Effect Unit
triggerEvent = runEffectFn2 _triggerEvent triggerEvent = runEffectFn2 _triggerEvent
------------------------------------------------------- -------------------------------------------------------
getInputValue :: R.Ref (Nullable DOM.Element) -> String
getInputValue elNullableRef = case toMaybe (R.readRef elNullableRef) of
Nothing -> ""
Just el ->
el .. "value"
setInputValue :: R.Ref (Nullable DOM.Element) -> String -> Effect Unit setInputValue :: R.Ref (Nullable DOM.Element) -> String -> Effect Unit
setInputValue elNullableRef val = case toMaybe (R.readRef elNullableRef) of setInputValue elNullableRef val = case toMaybe (R.readRef elNullableRef) of
Nothing -> pure unit Nothing -> pure unit
......
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