Commit bab9f124 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[search] some refactorings for search input box

parent 39a3fdef
...@@ -273,6 +273,33 @@ loadedNgramsTable :: R2.Component PropsNoReload ...@@ -273,6 +273,33 @@ loadedNgramsTable :: R2.Component PropsNoReload
loadedNgramsTable = R.createElement loadedNgramsTableCpt loadedNgramsTable = R.createElement loadedNgramsTableCpt
loadedNgramsTableCpt :: R.Component PropsNoReload loadedNgramsTableCpt :: R.Component PropsNoReload
loadedNgramsTableCpt = here.component "loadedNgramsTable" cpt where loadedNgramsTableCpt = here.component "loadedNgramsTable" cpt where
cpt props@{ path } _ = do
searchQuery <- T.useFocused (_.searchQuery) (\a b -> b { searchQuery = a }) path
pure $ R.fragment $
[ loadedNgramsTableHeader { searchQuery } []
, loadedNgramsTableBody props [] ]
type LoadedNgramsTableHeaderProps =
( searchQuery :: T.Box SearchQuery )
loadedNgramsTableHeader :: R2.Component LoadedNgramsTableHeaderProps
loadedNgramsTableHeader = R.createElement loadedNgramsTableHeaderCpt
loadedNgramsTableHeaderCpt :: R.Component LoadedNgramsTableHeaderProps
loadedNgramsTableHeaderCpt = here.component "loadedNgramsTableHeader" cpt where
cpt { searchQuery } _ = do
pure $ R.fragment
[ H.h4 {style: {textAlign : "center"}}
[ H.span {className: "fa fa-hand-o-down"} []
, H.text "Extracted Terms" ]
, NTC.searchInput { key: "search-input"
, searchQuery }
]
loadedNgramsTableBody :: R2.Component PropsNoReload
loadedNgramsTableBody = R.createElement loadedNgramsTableBodyCpt
loadedNgramsTableBodyCpt :: R.Component PropsNoReload
loadedNgramsTableBodyCpt = here.component "loadedNgramsTableBody" cpt where
cpt { afterSync cpt { afterSync
, boxes: { errors , boxes: { errors
, tasks } , tasks }
...@@ -370,14 +397,8 @@ loadedNgramsTableCpt = here.component "loadedNgramsTable" cpt where ...@@ -370,14 +397,8 @@ loadedNgramsTableCpt = here.component "loadedNgramsTable" cpt where
<<< _Just <<< _Just
) =<< ngramsParent ) =<< ngramsParent
pure $ R.fragment $ pure $ R.fragment
autoUpdate path' <> [ TT.table
[ H.h4 {style: {textAlign : "center"}}
[ H.span {className: "fa fa-hand-o-down"} []
, H.text "Extracted Terms" ]
, NTC.searchInput { key: "search-input"
, searchQuery }
, TT.table
{ colNames { colNames
, container: tableContainer , container: tableContainer
{ dispatch: performAction { dispatch: performAction
......
...@@ -25,7 +25,6 @@ import Gargantext.Components.NgramsTable.Core ...@@ -25,7 +25,6 @@ import Gargantext.Components.NgramsTable.Core
( Action(..), Dispatch, NgramsElement, NgramsTable, NgramsTablePatch, NgramsTerm ( Action(..), Dispatch, NgramsElement, NgramsTable, NgramsTablePatch, NgramsTerm
, _NgramsElement, _NgramsRepoElement, _PatchMap, _children, _list , _NgramsElement, _NgramsRepoElement, _PatchMap, _children, _list
, _ngrams, _occurrences, ngramsTermText, replace, setTermListA ) , _ngrams, _occurrences, ngramsTermText, replace, setTermListA )
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as Tbl import Gargantext.Components.Table as Tbl
import Gargantext.Types as T import Gargantext.Types as T
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
...@@ -38,38 +37,51 @@ type SearchInputProps = ...@@ -38,38 +37,51 @@ type SearchInputProps =
, searchQuery :: T.Box String , searchQuery :: T.Box String
) )
searchInput :: Record SearchInputProps -> R.Element searchInput :: R2.Leaf SearchInputProps
searchInput props = R.createElement searchInputCpt props [] searchInput props = R.createElement searchInputCpt props []
searchInputCpt :: R.Component SearchInputProps searchInputCpt :: R.Component SearchInputProps
searchInputCpt = here.component "searchInput" cpt searchInputCpt = here.component "searchInput" cpt
where where
cpt { searchQuery } _ = do cpt { searchQuery } _ = do
searchQuery' <- T.useLive T.unequal searchQuery
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 searchQuery' [ searchButton { searchQuery } []
, fieldInput searchQuery' , searchFieldInput { searchQuery } []
] ]
] ]
] ]
where
searchButton searchQuery' = type SearchButtonProps =
H.div { className: "input-group-prepend" } ( searchQuery :: T.Box String
)
searchButton :: R2.Component SearchButtonProps
searchButton = R.createElement searchButtonCpt
searchButtonCpt :: R.Component SearchButtonProps
searchButtonCpt = here.component "searchButton" cpt where
cpt { searchQuery } _ = do
searchQuery' <- T.useLive T.unequal searchQuery
pure $ H.div { className: "input-group-prepend" }
[ if searchQuery' /= "" [ if searchQuery' /= ""
then removeButton then
else H.span { className: "fa fa-search input-group-text" } []
]
removeButton =
H.button { className: "btn btn-danger" H.button { className: "btn btn-danger"
, on: {click: \e -> T.write "" searchQuery}} , on: {click: \_ -> T.write "" searchQuery}}
[ H.span {className: "fa fa-times"} []] [ H.span {className: "fa fa-times"} []]
else H.span { className: "fa fa-search input-group-text" } []
]
type SearchFieldInputProps =
( searchQuery :: T.Box String
)
fieldInput searchQuery' = searchFieldInput :: R2.Component SearchFieldInputProps
H.input { className: "form-control" searchFieldInput = R.createElement searchFieldInputCpt
, defaultValue: searchQuery' searchFieldInputCpt :: R.Component SearchFieldInputProps
searchFieldInputCpt = here.component "searchFieldInput" cpt where
cpt { searchQuery } _ = do
pure $ H.input { className: "form-control"
, name: "search" , name: "search"
, on: { input: \e -> T.write (R.unsafeEventValue e) searchQuery } , on: { input: \e -> T.write (R.unsafeEventValue e) searchQuery }
, placeholder: "Search" , placeholder: "Search"
......
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