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
b642764a
Commit
b642764a
authored
Dec 19, 2019
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev-warnings-cleanup' into dev-sigmajs-selector
parents
6db0c594
00bcbcee
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
68 deletions
+94
-68
SearchBar.purs
src/Gargantext/Components/Search/SearchBar.purs
+4
-35
SearchField.purs
src/Gargantext/Components/Search/SearchField.purs
+90
-33
No files found.
src/Gargantext/Components/Search/SearchBar.purs
View file @
b642764a
...
...
@@ -6,12 +6,13 @@ import Prelude (Unit, bind, discard, pure, ($))
import Data.Maybe (Maybe(..))
import Data.Newtype (over)
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff, launchAff_)
import Effect (Effect)
import Effect.Class (liftEffect)
import Reactix as R
import DOM.Simple.Console (log2)
import Effect.Aff (Aff, launchAff_)
import Reactix.DOM.HTML as H
import Gargantext.Components.Search.Types -- (Database, SearchQuery(..), defaultSearchQuery, performSearch, Lang(..))
import Gargantext.Components.Modals.Modal (modalShow)
import Gargantext.Components.Search.SearchField (Search, searchField)
...
...
@@ -29,38 +30,6 @@ searchBarCpt :: R.Component Props
searchBarCpt = R.hooksComponent "G.C.Node.SearchBar.searchBar" cpt
where
cpt {session, langs, search: search@(s /\ _)} _ = do
onSearchChange session s
--
onSearchChange session s
pure $ H.div {"style": {"margin" :"10px"}}
[ searchField {databases:allDatabases, langs, search}]
onSearchChange :: Session -> Search -> R.Hooks Unit
onSearchChange session s =
--R.useLayoutEffect1' search $ traverse_ triggerSearch search
--R.useEffect' $ traverse_ triggerSearch search
R.useEffectOnce' $ triggerSearch s
where
triggerSearch :: Search -> Effect Unit
triggerSearch q =
launchAff_ $ do
liftEffect $ do
-- log2 "Searching datafield: " $ show q.database
log2 "Searching term: " q.term
log2 "Searching lang: " q.lang
r <- (performSearch session $ searchQuery q) :: Aff Unit
liftEffect $ do
log2 "Return:" r
modalShow "addCorpus"
searchQuery :: Search -> SearchQuery
searchQuery {datafield: Nothing, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {datafield, lang, term, node_id} =
over SearchQuery (_ { datafield=datafield
, lang=lang
, query=term
, node_id=node_id
}) defaultSearchQuery
[ searchField {databases:allDatabases, langs, search, session}]
src/Gargantext/Components/Search/SearchField.purs
View file @
b642764a
module Gargantext.Components.Search.SearchField
( Search, Props, defaultSearch, searchField, searchFieldComponent, isIsTex) where
import Prelude (const, map, pure, show, discard, ($), (&&), (<), (<$>), (<>), (==), (<<<))
import Prelude (const, map, pure, show, discard, ($), (&&), (<), (<$>), (<>), (==), (<<<)
, Unit, bind
)
import Data.Maybe (Maybe(..), maybe)
import Data.Newtype (over)
import Data.String (length)
import Data.Set as Set
import Data.Tuple (fst)
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
import Effect (Effect)
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Components.Modals.Modal (modalShow)
import Gargantext.Components.Search.Types -- (Database(..), readDatabase, Lang(..), readLang, Org(..), readOrg, allOrgs, allIMTorgs, HAL_Filters(..), IMT_org(..))
import Gargantext.Sessions (Session)
select :: forall props.
R.IsComponent String props (Array R.Element)
...
...
@@ -45,13 +52,16 @@ type Props =
, langs :: Array Lang
-- State hook for a search, how we get data in and out
, search :: R.State Search
, session :: Session
)
searchField :: Record Props -> R.Element
searchField p = R.createElement searchFieldComponent p []
searchFieldComponent :: R.Memo Props
searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) eqProps
--searchFieldComponent :: R.Memo Props
--searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) eqProps
searchFieldComponent :: R.Component Props
searchFieldComponent = R.hooksComponent "G.C.S.SearchField" cpt
where
cpt props@{search: search@(s /\ _)} _ = do
pure $
...
...
@@ -60,7 +70,7 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) eqProps
H.div { className: "row" }
[
H.div { className: "col-md-12" }
[ searchInput
search
[ searchInput
{search}
, if length s.term < 3
then
H.div {}[]
...
...
@@ -87,11 +97,11 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) eqProps
, H.div { className : "panel-footer" }
[ if needsLang s.datafield then langNav search props.langs else H.div {} []
, H.div {} []
, H.div {className: "flex-center"} [submitButton
search
]
, H.div {className: "flex-center"} [submitButton
{search, session: props.session}
]
]
]
eqProps
p p' = (fst p.search == fst p'.search)
&&
(p.databases == p'.databases )
eqProps
:: Record Props -> Record Props -> Boolean
eqProps p p' =
(p.databases == p'.databases )
&& (p.langs == p'.langs )
&& (eqSearch (fst p.search) (fst p'.search))
-- && (fst p.filters == fst p'.filters )
...
...
@@ -293,31 +303,78 @@ filterInput (term /\ setTerm) =
]
searchInput :: R.State Search -> R.Element
searchInput ({term} /\ setSearch) =
type SearchInputProps =
(
search :: R.State Search
)
searchInput :: Record SearchInputProps -> R.Element
searchInput p = R.createElement searchInputComponent p []
searchInputComponent :: R.Component SearchInputProps
searchInputComponent = R.hooksComponent "G.C.S.SearchInput" cpt
where
cpt {search: (search /\ setSearch)} _ = do
pure $
H.div { className : "" }
[ H.input { defaultValue:
term
[ H.input { defaultValue: search.
term
, className: "form-control"
, type: "text"
, on: { change : onChange
}
, on: { change : onChange setSearch
}
, placeholder: "Your Query here" }
]
where
onChange e = do
setSearch $ _ { term = R2.unsafeEventValue e }
onChange setSearch e = do
let value = R2.unsafeEventValue e
setSearch $ _ { term = value }
type SubmitButtonProps =
(
search :: R.State Search
, session :: Session
)
submitButton :: Record SubmitButtonProps -> R.Element
submitButton p = R.createElement submitButtonComponent p []
submitButton :: R.State Search
-> R.Element
submitButton (search /\ setSearch) =
submitButtonComponent :: R.Component SubmitButtonProps
submitButtonComponent = R.hooksComponent "G.C.S.SubmitButton" cpt
where
cpt {search: search /\ setSearch, session} _ =
pure $
H.button { className: "btn btn-primary"
, type: "button"
, on: {click: doS
earch}
, on: {click: doSearch session s
earch}
, style: { width: "100%" }
} [ H.text "Launch Search" ]
where
doSearch = \_ -> do
log2 "[submitButton] searching" search
case search.term of
"" -> setSearch $ const defaultSearch
_ -> setSearch $ const search
doSearch s q = \_ -> do
log2 "[submitButton] searching" q
triggerSearch s q
--case search.term of
-- "" -> setSearch $ const defaultSearch
-- _ -> setSearch $ const q
triggerSearch :: Session -> Search -> Effect Unit
triggerSearch s q =
launchAff_ $ do
liftEffect $ do
-- log2 "Searching datafield: " $ show q.database
log2 "Searching term: " q.term
log2 "Searching lang: " q.lang
r <- (performSearch s $ searchQuery q) :: Aff Unit
liftEffect $ do
log2 "Return:" r
modalShow "addCorpus"
searchQuery :: Search -> SearchQuery
searchQuery {datafield: Nothing, term} =
over SearchQuery (_ {query=term}) defaultSearchQuery
searchQuery {datafield, lang, term, node_id} =
over SearchQuery (_ { datafield=datafield
, lang=lang
, query=term
, node_id=node_id
}) defaultSearchQuery
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